Replies: 1 comment
-
|
This error comes from SQLAlchemy's You have two clean options. Option A — store plain dicts (simplest)Type the column as JSON-native data and dump your models before assigning: from typing import Any
from sqlmodel import Field, SQLModel, Column, JSON
class Action(SQLModel):
title: str
location: str
description: str | None = None
class Hero(SQLModel, table=True):
id: int | None = Field(default=None, primary_key=True)
name: str
actions: list[dict[str, Any]] = Field(default_factory=list, sa_column=Column(JSON))
hero = Hero(
name="Deadpond",
actions=[a.model_dump() for a in (Action(title="t", location="l"),)],
)Read them back as models with Option B — keep
|
Beta Was this translation helpful? Give feedback.
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
sqlalchemy.exc.StatementError: (builtins.TypeError) Object of type Action is not JSON serializable
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.38
Python Version
3.14
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions