You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question and didn't find it.
I searched the SQLModel documentation, with the integrated search.
I already searched in Google "How to X in SQLModel" and didn't find any information.
I already read and followed all the tutorial in the docs and didn't find an answer.
I already checked if it is not related to SQLModel but to Pydantic.
I already checked if it is not related to SQLModel but to SQLAlchemy.
Commit to Help
I commit to help with one of those options 👆
Example Code
fromtypingimportAnnotated, TypeAliasfromsqlmodelimportField, SQLModeltypeId=Annotated[int, Field(primary_key=True)]
# Changing to this works:# Id: TypeAlias = Annotated[int, Field(primary_key=True)]classHasAnnotatedColumn(SQLModel, table=True):
id: Id
Description
Using typing.Annotated + type statement results in:
Traceback (most recent call last):
File "/workspaces/maven.tse.opsdata/repro.py", line 8, in <module>
class HasAnnotatedColumn(SQLModel, table=True):
File "/workspace/.venv/lib/python3.12/site-packages/sqlmodel/main.py", line 559, in __new__
col = get_column_from_field(v)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/.venv/lib/python3.12/site-packages/sqlmodel/main.py", line 708, in get_column_from_field
sa_type = get_sqlalchemy_type(field)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/.venv/lib/python3.12/site-packages/sqlmodel/main.py", line 656, in get_sqlalchemy_type
if issubclass(type_, Enum):
^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class
There is a workaround available by using a TypeAlias instead of a type statement; the type statement results in a typing.TypeAliasType, which has a __value__ property that has the aliased type definition.
This is similar to #67 , but I suspect a slightly different use case/problem.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
Using
typing.Annotated
+type
statement results in:Operating System
Linux
Operating System Details
cat /etc/os-release
:PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
SQLModel Version
0.0.22
Python Version
Python 3.12.7
Additional Context
There is a workaround available by using a
TypeAlias
instead of atype
statement; thetype
statement results in atyping.TypeAliasType
, which has a__value__
property that has the aliased type definition.This is similar to #67 , but I suspect a slightly different use case/problem.
Beta Was this translation helpful? Give feedback.
All reactions