-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] Updating documents with a frozen BaseModel as field raises TypeError #599
Comments
Actually, it looks like class PersonDetails(BaseModel):
ssn: int
dob: str
class Config:
frozen = True
class Person(Document):
first_name: str
last_name: str
details: PersonDetails
class Settings:
use_state_management = True
await init_beanie(database=db, document_models=[Person])
person = Person(first_name="john", last_name="doe", details=PersonDetails(ssn=123, dob="01/01/1970"))
await person.insert()
print(f"Created {person=}")
person.first_name = "jane"
# await person.save() # TypeError: "PersonDetails" is immutable and does not support item assignment
await person.save_changes() # TypeError: "PersonDetails" is immutable and does not support item assignment
print(f"Updated {person=}") The
|
In 1.17.0 this doesn't occur, it seems to have been introduced in 1.18.0 |
Hello, |
Just ran into this as well. Rolling back to 1.17.0 took care of the issue |
This bug is fixed in #669. Please try |
Thank you! Actually it already seems to have been fixed in version 1.21.0, when I upgrade to that version all of our testcases pass (and on 1.20.0 they didn't pass yet). Awesome :) When I |
Describe the bug
Relating a document X to document Y using
Link[]
, with document Y having apydantic.BaseModel
field that hasclass Config: frozen = True
, will trigger the errorTypError: <field> is immutable
in Pydantic.To Reproduce
edit please check my comment below, there is an easier way to reproduce it.
Outputs:
When I first create the
Person
document and then try to link this to theHouse
, it fails on the linking action;It successfully performs
person.insert()
and then raises the error at the `house.insert():Ways to not get this error:
link_rule=WriteRules.WRITE
(viable workaround, but quite verbose)frozen = True
(not a viable workaround in my case)Expected behavior
Same as when
Person
would not be a Document but just a BaseModel;Which inserts without problems:
Additional context
n/a
The text was updated successfully, but these errors were encountered: