Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DictField is auto-dereferenced if storing data containing _cls property #1398

Open
robertaistleitner opened this issue Nov 17, 2016 · 5 comments
Labels

Comments

@robertaistleitner
Copy link

This bug already existed some time ago (#1058) and there was even a bugfix for it (#1088) but I'm still experiencing this issue..

The bugfix doesn't work for me and I think the test case is not written in a correct way. I'm not sure but it looks like the DictField is auto-dereferenced if it's loaded from the database - which never happens in the test case.

I was able to track down the issue to it's root cause, which is here: https://github.com/MongoEngine/mongoengine/blob/master/mongoengine/base/document.py#L705

The _auto_dereference setting for the DictField is just ignored and overridden, which causes strange behaviour when accessing the field. First it looks like it's a normal instance of a Document, then it's a list with just the property names.

@robertaistleitner
Copy link
Author

@thedrow would be awesome if you could join the discussion over here again.. 😉

@robertaistleitner
Copy link
Author

@thedrow do you have any (good) news for me? stumbled again over this issue as this needs a workaround every time..

@thedrow
Copy link
Contributor

thedrow commented Nov 30, 2016

I haven't found the time to look into it yet.

@robertaistleitner
Copy link
Author

I just found another issue caused by this bug.. Saving the same document more than one time doesn't work because it replaces the DictField value with a DBRef, which causes validation to fail at the second save.

@lafrech lafrech added the Bug label Nov 30, 2016
@bagerard
Copy link
Collaborator

bagerard commented Sep 2, 2018

The following is also a funky side effect of it:

class House(me.Document):
    address = me.StringField()
    meta = {'allow_inheritance': True}


class Person(me.Document):
    age = me.IntField()

Person(age=79).save()

# Let's force a house document in the person collection
dumped_house = House(address='garbage').to_mongo().to_dict()
Person._get_collection().insert_one(dumped_house)

print list(Person.objects())        # [<Person: Person object>, <House: House object>]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants