Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion sqlmodel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from sqlalchemy.orm.decl_api import DeclarativeMeta
from sqlalchemy.orm.instrumentation import is_instrumented
from sqlalchemy.sql.schema import MetaData
from sqlalchemy.sql.sqltypes import LargeBinary, Time, Uuid
from sqlalchemy.sql.sqltypes import JSON, LargeBinary, Time, Uuid
from typing_extensions import Literal, deprecated, get_origin

from ._compat import ( # type: ignore[attr-defined]
Expand Down Expand Up @@ -694,6 +694,9 @@ def get_sqlalchemy_type(field: Any) -> Any:
)
if issubclass(type_, uuid.UUID):
return Uuid
if issubclass(type_, JSON):
return JSON
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want issubclass(type_, Mapping) rather here?

Also it is probably not clear if JSON or JSONB is the desired type.

Maybe better to document the workaround in the docs

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be if issubclass(type_, pydantic.Json): instead?
Or better

    if issubclass(type_, (Sequence, Mapping, Json)):
        return JSON


raise ValueError(f"{type_} has no matching SQLAlchemy type")


Expand Down