MongoEngine / MongoEngine/mongoengine
Newly added embedded documents list field is None instead of list.
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:
- We start without the
drinkfield on theShopmodel.
Inside the database, documents at this time does not havedrinkkey inside. - Add the
drinksfield onto theShopdocument, the model we have now is exactly what's above. - At this point, we execute the following query:
shop_obj = Shop.objects.only('drinks').first()
- Here comes the bug and the reason for this issue, what should be
shop_obj.drinkshere ?
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
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 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