MongoEngine / MongoEngine/mongoengine

ListField(CachedReferenceField) does not auto sync

Open
#1,561 1 comment 1 reaction 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

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.