MongoEngine / MongoEngine/mongoengine

EmbeddedDocumentField does not properly merge meta if it already exists

Open
#1,894 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

For a project I am working on, I need both the merging of the meta dict and merging with the parent's meta dict (I am using a custom field in meta, coupled with inheritance on the EmbeddedDocuments themselves). However, this is not working properly. After quite a bit of searching, I traced it back to here. Note that there's no merging performed if the subclass specifies it's own meta. That meta is simply copied over to _meta, which means we lose allow_inheritance (which means we further lose _cls when saving EmbeddedDocument instances).

I am unsure of how to proceed here, but would be happy to open a PR. However, I don't know whether an unconditional merge of these two dictionaries is beneficial to all scenarios. If anyone has feedback on how to move forward here, please reply.

I am currently working around this by manually specifying the allow_inheritance field on the child classes. If any of this is unclear, please let me know and I will work up a small example.

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 in mongoengine/base/metaclasses.py at lines 34-47 and trace how EmbeddedDocument subclasses copy or merge meta. Build the small inheritance example mentioned in the issue, then verify how allow_inheritance and _cls behave when saving instances. Done means the intended parent and child metadata are preserved without breaking existing scenarios.

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.