MongoEngine / MongoEngine/mongoengine

EmbeddedDocumentListField default value issue

Open
#2,168 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

There's a EmbeddedDocumentListField ("Radios") that has default values: [Radio(), Radio()], the default value definition is modified after the data been stored in database so there's no value in database.

While get the EmbeddedDocumentListField default value everything is fine, but there's something wrong when update some value of the default value in the List.

radio = network.radios.get(type=xxx)
radio.is_enable = True
network.save()

Database wrong data:
"radios": {
   "0": {
       "is_enable": true
   }
} 

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 by reproducing the EmbeddedDocumentListField default-value case with [Radio(), Radio()] and the shown network.save() update. Inspect how the default list is loaded and persisted, then verify that changing a nested Radio value stores the complete embedded list rather than the malformed "radios": {"0": ...} shape.

Written by the indexing model from the issue text.

Assessment

Tech stack
mongodb, python
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.