Skip to content

Conversation

@kleschenko
Copy link

I noticed a problem while trying to use optional fields with custom types. Using an optional UUID4 field (entity_id: UUID4 | None = Field(default=None, foreign_key="entity.id")) gives me an error:

...
  File "/home/user/.pyenv/versions/3.11.5/envs/env/lib/python3.11/site-packages/sqlmodel/main.py", line 358, in __new__
    col = get_column_from_field(v)
          ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.pyenv/versions/3.11.5/envs/env/lib/python3.11/site-packages/sqlmodel/main.py", line 540, in get_column_from_field
    sa_type = get_sqlalchemy_type(field)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/user/.pyenv/versions/3.11.5/envs/env/lib/python3.11/site-packages/sqlmodel/main.py", line 484, in get_sqlalchemy_type
    if issubclass(type_, str) or type_ in (EmailStr, NameEmail, ImportString):
       ^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class

This PR fixes the problem by using the original type instead of the annotation

@AntonDeMeester AntonDeMeester merged commit b3308d7 into AntonDeMeester:main Oct 12, 2023
@kleschenko kleschenko deleted the patch-1 branch October 13, 2023 11:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants