Added _instance for EmbeddedDocument then accessing dict values #2754
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
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.