MongoEngine / MongoEngine/mongoengine
DictField is auto-dereferenced if storing data containing _cls property
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
This bug already existed some time ago (https://github.com/MongoEngine/mongoengine/issues/1058) and there was even a bugfix for it (https://github.com/MongoEngine/mongoengine/pull/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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at mongoengine/base/document.py around line 705 and reproduce the DictField behavior with data containing an _cls property loaded from the database. Review the existing regression test from the fix referenced in issues #1058 and pull request #1088, then ensure the test covers database loading and distinguishes a DictField value from an auto-dereferenced Document.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100