MongoEngine / MongoEngine/mongoengine

DictField is auto-dereferenced if storing data containing _cls property

Open
#1,398 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.