Open roman-right opened 1 year ago
Hey @tomohirohiratsuka Sorry for the delay.
I see the problem, but I'd like to have a use case, when it appears. Could you please give me a one-module example for it? Thank you
import asyncio
from beanie import init_beanie, Document
class Directory(Document):
name: str
file_names: list[str]
async def main():
await init_beanie(connection_string="mongodb://localhost:27017/test", document_models=[Directory])
files = ['file-1', 'file-2', 'file-3']
directory = await Directory(name='dir-1', file_names=files).insert()
new_files = ['file-1']
new_directory = await directory.set(dict(file_names=new_files))
assert new_directory.file_names == new_files
asyncio.run(main())
Here is the code that can reproduce this bug
Hey @tomohirohiratsuka Sorry for the delay.
I see the problem, but I'd like to have a use case, when it appears. Could you please give me a one-module example for it? Thank you
@roman-right Hi, Thank you for your response. I've made a simple reproduction repo. https://github.com/tomohirohiratsuka/beanie-reproduction-653 Please take a look at it.
Hey @tomohirohiratsuka It looks like this case is solved in the 1.22 version. Could you please check?
@roman-right Hi, thank you for versioning up. I've confirmed that it's fixed on v1.22.1. https://github.com/tomohirohiratsuka/beanie-reproduction-653
Since this is solved, I've also closed my PR. Thank you.
I encountered an issue when attempting to update a document that includes a Link. I executed the update using the set
method, and the changes appeared in the database immediately. However, the object returned by merge_models
does not reflect the new link. Is this expected behavior?
model.set( {'my_link': {'id': '66d9b36467d68baa0b96849b', 'collection': 'MyLink'})
After reviewing the code of merge_models, I discovered the reason I'm not getting the expected result. In the final part of the code, it checks the type of the field and skips it if it’s a Link.
# starting from this line
elif not isinstance(right_value, Link):
left.__setattr__(k, right_value)
Can I ask why this is necessary?
Discussed in https://github.com/roman-right/beanie/discussions/652