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

Added _instance for EmbeddedDocument then accessing dict values #2754

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

GodMorduk
Copy link

In cases when we have a DictField and we have an EmbeddedDocument as a value of the dict, the values doesn't get _instance, thus not allowing us to reference parent document.

But then we get access value directly, we can have _instance set correctly. So basically there is a workaround, but the code became a bit messy.

Consider the following example, where "vars" is DictField with string in key and EmbeddedDocument in value:

# that won't work, would print "None"
for var in self.vars.values():
    print(var._instance)

# that is working, would print correct object
for var in self.vars:
   print(self.vars[var]._instance)

This small PR fixes it, as it seems like a bug, not an intended behaviour. Haven't found any issues with that, there is simply one extra isinstance check and impact on perfomance should not be noticable. It also shoud not cause any incompability with any existing projects using MongoEngine.

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.

1 participant