Querying a reference to a custom pk document is broken

This test fails on `self.assertEqual(B.objects.get(a=a.id).a, a)` with `InvalidId: custom_id is not a valid ObjectId`. It used to pass in previous versions of MongoEngine.