MongoEngine / MongoEngine/mongoengine
DynamicField doesn't save as a ListField
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Updating a DynamicField of a list does not update using .save() or .cascade_save() when the list is updated using .append().
System Info
Ubuntu 20.04 LTS
MongoDB v6.0.4
mongoengine v0.26.0
pymongo v3.12.3
Reproducible Example
class ExampleModel(DynamicDocument):
value = DynamicField()
Actual Result
>>> example = ExampleModel(value=[])
>>> example.value.append(1)
>>> example.save()
<ExampleModel: ExampleModel object>
>>> example.value
[1]
>>> example.reload()
<ExampleModel: ExampleModel object>
>>> example.value
[]
Expected Result
>>> example = ExampleModel(value=[])
>>> example.value.append(1)
>>> example.save()
<ExampleModel: ExampleModel object>
>>> example.value
[1]
>>> example.reload()
<ExampleModel: ExampleModel object>
>>> example.value
[1]
Work-Around
>>> example = ExampleModel(value=[])
>>> example.value.append(1)
>>> example.save()
<ExampleModel: ExampleModel object>
>>> a = list(example.value)
>>> a.append(1)
>>> example.value = a
>>> example.save()
>>> example.value
[1]
>>> example.reload()
<ExampleModel: ExampleModel object>
>>> example.value
[1]
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 with the DynamicField list-mutation path and the save()/cascade_save() behavior, using the reproducible ExampleModel case in the issue. Add a regression check that appending to an initially empty value persists after save and reload, and confirm the behavior for both save methods.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- database
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100