MongoEngine / MongoEngine/mongoengine

DynamicField doesn't save as a ListField

Open
#2,743 0 comments 0 reactions 0 assignees View on GitHub

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.