You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
When modifying a parameter and subsequently saving the model using .save(), I noticed an issue where a previously fetched BackLink field reverted its value from the fetched content back to a reference object.
Further use of the object model after saving may lead to errors.
To Reproduce
importasynciofrombeanieimportBackLink, Document, Link, init_beaniefrommotor.motor_asyncioimportAsyncIOMotorClientfrompydanticimportFieldclassTask(Document):
subtasks: list[BackLink["SubTask"]] =Field(json_schema_extra={"original_field": "related_task_id"})
n: int=0classSettings:
max_nesting_depths_per_field= {
"subtasks": 1# Nesting depth for a specific field
}
classSubTask(Document):
related_task_id: Link[Task]
index: int=0asyncdefmain():
db=AsyncIOMotorClient(
'mongodb://admin:[email protected]/?retryWrites=true&w=majority',
serverSelectionTimeoutMS=5000
)['beanie_trouble_test']
awaitinit_beanie(db, document_models=[Task, SubTask])
# preparingtask=awaitTask().save()
awaitSubTask(related_task_id=task.id, index=1).save()
awaitSubTask(related_task_id=task.id, index=2).save()
awaitSubTask(related_task_id=task.id, index=3).save()
# testingtask=awaitTask.get(task.id, fetch_links=True)
print("fetched task: ", task)
print("list of subtasks:")
forsubintask.subtasks:
print(sub)
task.n=100awaittask.save()
print("task after saving: ", task)
print("list of subtasks:")
forsubintask.subtasks:
print(sub)
if__name__=='__main__':
asyncio.run(main())
logs:
fetched task: id=ObjectId('66c498fb13d341db6da587bc') revision_id=None subtasks=[SubTask(id=ObjectId('66c498fb13d341db6da587bd'), revision_id=None, related_task_id=<beanie.odm.fields.Link object at 0x000002A7DE947610>, index=1), SubTask(id=ObjectId('66c498fb13d341db6da587be'), revision_id=None, related_task_id=<beanie.odm.fields.Link object at 0x000002A7DE947650>, index=2), SubTask(id=ObjectId('66c498fb13d341db6da587bf'), revision_id=None, related_task_id=<beanie.odm.fields.Link object at 0x000002A7DE946890>, index=3)] n=0
list of subtasks:
id=ObjectId('66c498fb13d341db6da587bd') revision_id=None related_task_id=<beanie.odm.fields.Link object at 0x000002A7DE947610> index=1
id=ObjectId('66c498fb13d341db6da587be') revision_id=None related_task_id=<beanie.odm.fields.Link object at 0x000002A7DE947650> index=2
id=ObjectId('66c498fb13d341db6da587bf') revision_id=None related_task_id=<beanie.odm.fields.Link object at 0x000002A7DE946890> index=3
task after saving: id=ObjectId('66c498fb13d341db6da587bc') revision_id=None subtasks=[<beanie.odm.fields.BackLink object at 0x000002A7DE947210>] n=100
list of subtasks:
<beanie.odm.fields.BackLink object at 0x000002A7DE947210>
Expected behavior
I guess, saving should either keep content unchanged or fetch it fully with updated data Additional context
beanie==1.26.0
pydantic==2.8.2
The text was updated successfully, but these errors were encountered:
virrius
changed the title
[BUG] BackLink field value replacing with link url object on save()
[BUG] BackLink field value replacing with link object on save()
Aug 20, 2024
Describe the bug
When modifying a parameter and subsequently saving the model using .save(), I noticed an issue where a previously fetched BackLink field reverted its value from the fetched content back to a reference object.
Further use of the object model after saving may lead to errors.
To Reproduce
logs:
Expected behavior
I guess, saving should either keep content unchanged or fetch it fully with updated data
Additional context
beanie==1.26.0
pydantic==2.8.2
The text was updated successfully, but these errors were encountered: