-
-
Notifications
You must be signed in to change notification settings - Fork 717
Field(allow_mutation=False) doesn't have same behavior as pydantic #262
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
Comments
Several issues have been reported about inconsistencies between sqlmodel and pydantic: #87, #230, etc. This particular issue is caused by these lines in main.py:
The last line is assignment, which is forbidden by |
I also hope the immutatable model can be possible in sqlmodel. The same problem is reported in stackoverflow here The problem still exists in 0.0.8 |
Hi! Does the recent version of SQLModel (0.0.14) solves the issue? :) |
I am having the same problem at version 0.0.24, and even setting Below is an example stacktrace, where date_of_creation: datetime = Field(
# allow_mutation=True, # This seems meaningless as it is a pydantic v1 argument
default_factory=datetime.now,
schema_extra={"frozen": True} # see https://github.com/fastapi/sqlmodel/issues/262#issuecomment-1060041950
) The stacktrace is as follows:
The last callstack at the SQLModel side is here. I wanted to fix it, but it seems so deep down in the callstack, and is nested inside multiple dunder method calls, so I have no idea how to even start fixing that. Also, can we get a |
First Check
Commit to Help
Example Code
Description
When setting a
Field(allow_mutation=False)
in combination with the requiredvalidate_assignment = True
configuration on aSQLModel
, the framework doesn't even allow the field to be set in the initial construction of the model. This is allowed inpydantic
. I've attached a test suite that we should expect to pass, but it fails both theSQLModel
specific tests.Operating System
macOS
Operating System Details
Big Sur 11.3.1
SQLModel Version
0.0.6
Python Version
3.9.9
Additional Context
No response
The text was updated successfully, but these errors were encountered: