Passing schema_extra
to Field has changed in Pydantic 2.0 but not in SQLModel.
#833
Replies: 6 comments 2 replies
-
Okay, it's been over a week and I am fairly positive this is a bug. So tagging @tiangolo, @maru0123-2004 @daniil-berg, @raphaelgibson based on who have made commits to the lines surrounding the bug. I'll appreciate the help, thank you! |
Beta Was this translation helpful? Give feedback.
-
@tiangolo Gentle reminder here. |
Beta Was this translation helpful? Give feedback.
-
Same issue. There is a prevision of when it would be changed? |
Beta Was this translation helpful? Give feedback.
-
Same issue. |
Beta Was this translation helpful? Give feedback.
-
Sorry for late replying. There may exists problem for argument naming, but it is not bad than mine. My contribution is not affected to this problem, I think. But if there are more problem having relation with my code, please mention again. P.S. Sorry for bad my English. |
Beta Was this translation helpful? Give feedback.
-
The behavior is even more cursed if you try and work around it by using from sqlmodel import SQLModel
from pydantic import Field
class MyModel(SQLModel):
x: int = Field(json_schema_extra={'key': 'value'})
MyModel.model_fields['x']
# FieldInfo(..., json_schema_extra={'schema_extra': {'json_schema_extra': {'key': 'so'}}}) |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
PydanticV1's
Field
class supported passing arbitrary keyword arguments to the JSON schema. In SQLModel counterpart, it was supported by passingschema_extra
(see this).PydanticV2 still supports passing extra things to the JSON schema but in a slightly different way. One has to pass a dictionary in the
json_schema_extra
argument (see this).Currently, SQLModel does not reflect the corresponding change in its Field implementation. From what I can tell, it's simply about making one line change to the call here (call to Pydantic's FieldInfo).
For consistency with Pydantic, it may also be better to rename
schema_extra
tojson_schema_extra
.Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.16
Python Version
3.11.0
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions