Skip to content

Conversation

@bagerard
Copy link
Collaborator

Similarly to how #1892 fixed the issue for ReferenceField, this PR fixes the issue for GenericReferenceField that is suffering from the exact same issue. See below:

class Organization(me.Document):
    name = me.StringField()
    
class User(me.Document):
    name = me.StringField()
    organization = me.GenericReferenceField()

organization = Organization(name='Github').save()
User(name='John', organization=organization).save()

user = User.objects.first()   # fetch an instance before the no_dereference call
user_no_derf = User.objects.no_dereference().first() # alters the _auto_dereference of the class field (i.e the ReferenceField descriptor) 

print(user_no_derf.organization)    # {'_cls': 'Organization', '_ref': DBRef('organization', ObjectId('5baaa27e4ec5dc49f0ffc86a'))} (This is fine)
print(user.organization)    # Should be an Organization instance but is 
                            # {'_cls': 'Organization', '_ref': DBRef('organization', ObjectId('5baaa27e4ec5dc49f0ffc86a'))}


@erdenezul erdenezul merged commit 17b140b into MongoEngine:master Sep 25, 2018
@bagerard bagerard deleted the fix_side_effect_no_dereference_on_GenericReferenceField branch October 27, 2018 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants