MongoEngine / MongoEngine/mongoengine

Newly added embedded documents list field is None instead of list.

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

Dear maintainers:
With this issue I present an unexpected scenario that I've encountered recently for discussion.

Related models for this issue:

class Drink(EmbeddedDocument):
    cost = IntField()

class Shop(Document):
    name = StringField()
    drinks = EmbeddedDocumentListField(Drink)  # Our focus in this issue

Scenario:

  1. We start without the drink field on the Shop model.
    Inside the database, documents at this time does not have drink key inside.
  2. Add the drinks field onto the Shop document, the model we have now is exactly what's above.
  3. At this point, we execute the following query:
shop_obj = Shop.objects.only('drinks').first()
  1. Here comes the bug and the reason for this issue, what should be shop_obj.drinks here ?
    I expected it to be [], but apparently it's `None.

So what should it be ? An empty list or None ? I'm not sure what's the intended outcome here.
Me personally think it should be an empty list due to the fact that it is what I've defined on the model, and if that's the case I can open a PR regarding this issue. Just need confirmation on this behavior/direction with you guys.
Thanks.

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 issue with the shown Drink and Shop models and the Shop.objects.only('drinks').first() query. Determine the intended value for an omitted EmbeddedDocumentListField, then add a regression test covering newly added fields and verify the resulting value matches the project decision.

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.