Replies: 8 comments 2 replies
-
@DurandA I was facing the same issue thanks for creating this! |
Beta Was this translation helpful? Give feedback.
-
Looks like the pydantic SchemaValidator.validate_python (https://docs.pydantic.dev/latest/api/pydantic_core/#pydantic_core._pydantic_core.SchemaValidator.validate_python) doesn't handle aliases. That is what is used to set the fields of an object here: |
Beta Was this translation helpful? Give feedback.
-
related: #774 |
Beta Was this translation helpful? Give feedback.
-
I can't make .model_dump(by_alias=True) work. It always uses the attribute name. |
Beta Was this translation helpful? Give feedback.
-
Reproduced on SQLModel 0.0.16. upd: works by using #290 |
Beta Was this translation helpful? Give feedback.
-
Did anyone find a workaround? The one mentioned in #290 seems to be working only for table-models. |
Beta Was this translation helpful? Give feedback.
-
Also facing this issue |
Beta Was this translation helpful? Give feedback.
-
for me this workaround works for pydanticv 2.6 sqlmodel 0.0.14 its similar to what #774 does from sqlmodel import SQLModel, Field
class Test:
def __init__(self, test):
self.Test = test
class Item(SQLModel):
test: str = Field(schema_extra={"validation_alias": "Test"})
t1= Test("1")
Item.model_validate(t1)
Item.model_validate({"Test": "1"}) |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
Model
with aField
that contain an aliasOperating System
Linux
Operating System Details
No response
SQLModel Version
0.0.14
Python Version
Python 3.12.0
Additional Context
This issue appeared on SQLModel 0.0.14.
Beta Was this translation helpful? Give feedback.
All reactions