MongoEngine / MongoEngine/mongoengine
ListField(CachedReferenceField) does not auto sync
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.3k
- Forks
- 1.2k
- Avg merge
- 4h 41m
- Merged PRs (30d)
- 11
Description
Extending on #1560 I discovered that Lists of CachedReferenceField do not receive the updates to the cached fields when the master record is updated.
from mongoengine import *
from mongoengine.connection import get_db
from mongoengine.base import (BaseDict, BaseField, EmbeddedDocumentList,
_document_registry)
class Owner(EmbeddedDocument):
name = StringField()
tags = ListField(StringField())
class Animal(Document):
name = StringField()
tag = StringField()
owner = EmbeddedDocumentField(Owner)
class Ocorrence(Document):
person = StringField()
animal = ListField(CachedReferenceField(
Animal, fields=['tag', 'owner.tags']))
Animal.drop_collection()
Ocorrence.drop_collection()
a = Animal(name="Leopard", tag="heavy",
owner=Owner(tags=['cool', 'funny'],
name="Wilson Júnior")
)
a2 = Animal(name="Tiger", tag="too heavy",
owner=Owner(tags=['cool2', 'funny2'],
name="Wilson")
)
a.save()
a2.save()
o = Ocorrence(person="teste 2", animal=[a,a2])
o.save()
a.tag="Very Heavy"
a.save()
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 provided example with ListField(CachedReferenceField) and trace how CachedReferenceField updates are handled for list references. Done means updating and saving the master Animal refreshes the corresponding cached fields in the Ocorrence.animal list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, python
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100