MongoEngine / MongoEngine/mongoengine
Dict field in mongoengine does not save None types
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
When adding a new field to Dict type if the value is None key is never saved.
Attaching the code snippet below
import mongoengine
from mongoengine import *
class Test(Document):
args = DictField()
test = Test(args={'hello': None})
test.save()
#create a new key count with None
test.args['count'] = None
test.save()
for item in Test.objects:
print(item.args)
Output:
connected
{'hello': None}
Count with None is never saved !
But when doing this:
import mongoengine
from mongoengine import *
class Test(Document):
args = DictField()
test = Test(args={'hello': None})
test.save()
test.args['count'] = '1'
test.save()
for item in Test.objects:
print(item.args)
Output:
connected
{'hello': None, 'count': '1'}
When count is a non-None value it is saved
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 by running the provided Python reproduction with DictField and compare saving a newly added None value with a non-None value. Trace how the DictField contents are persisted during the second save. Done means a newly added key whose value is None is present after saving and reading the document again.
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