Repository navigation
Replies: 1 comment
|
After validating the fields, For the input in your example, validate a separate input model first, then construct the table object from the validated fields: class InvoiceCreate(SQLModel): # no table=True or relationships
customer: str
payload = InvoiceCreate.model_validate({"customer": "ABC"})
inv = Invoice(**payload.model_dump())
assert inv.customer == "ABC"
assert inv.items == []Keep your existing I reproduced the original exception with SQLModel 0.0.19, Pydantic 2.8.2 and SQLAlchemy 2.0.55. The input-model version rejects an invalid customer, and a SQLite insert/reload with an attached The separate data/table model pattern is also covered in the SQLModel tutorial. Prepared with AI assistance; reproduction, validation and SQLite persistence checked locally. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
On running this code:
inv=Invoice.model_validate({'customer':'ABC'})I get this error:
TypeError: Incompatible collection type: builtin_function_or_method is not list-likeOperating System
Windows
Operating System Details
No response
SQLModel Version
0.0.19
Python Version
3.12.0
Additional Context
No response
All reactions