Fixes #2333 exception on comparison with missing id.

Issue also exists in the 3.8.x branch.