Queryset issue with GenericReferenceField

18 views
Skip to first unread message

Léo

unread,
May 17, 2013, 8:25:49 AM5/17/13
to mongoeng...@googlegroups.com
Hi,

I'm encountering issues with mongoengine queries when executed from several frontends.
Consider the following documents and script on this gist: https://gist.github.com/leo-naeka/b498a7746eb19b90b48c

As you can see, on a single machine, the query works as expected.
But, as you evolve on multiple nodes, dict key orders may vary. so that the pymongo request will sometimes be:
{'_types': 'Resource', 'acl.read_list': {'$in': [{'_ref': DBRef('user', ObjectId('51961d7d4ab63c143f1c7a81')), '_cls': 'User'}, {'_ref': DBRef('group', ObjectId('51961d7d4ab63c143f1c7a82')), '_cls': 'Group'}]}}
and sometimes:
{'_types': 'Resource', 'acl.read_list': {'$in': [{'_cls': 'User', '_ref': DBRef('user', ObjectId('51961d7d4ab63c143f1c7a81'))}, {'_cls': 'Group', '_ref': DBRef('group', ObjectId('51961d7d4ab63c143f1c7a82'))}]}}

This is because dict does not preserves order (and varies from one machine/VM to another) and because MongoDB seems to handle the whole data, and not key/values one by one...
This dict is created in GenericReferenceField to_mongo method: mongoengine/fields.py#L929

Did anyone of you have experienced this kind of issue?
Thanks!
Reply all
Reply to author
Forward
0 new messages