sqlmodel icon indicating copy to clipboard operation
sqlmodel copied to clipboard

TypeError: issubclass() arg 1 must be a class

Open Maypher opened this issue 3 years ago • 1 comments

First Check

  • [X] I added a very descriptive title to this issue.
  • [X] I used the GitHub search to find a similar issue and didn't find it.
  • [X] I searched the SQLModel documentation, with the integrated search.
  • [X] I already searched in Google "How to X in SQLModel" and didn't find any information.
  • [X] I already read and followed all the tutorial in the docs and didn't find an answer.
  • [X] I already checked if it is not related to SQLModel but to Pydantic.
  • [X] I already checked if it is not related to SQLModel but to SQLAlchemy.

Commit to Help

  • [X] I commit to help with one of those options 👆

Example Code

from datetime import date
from typing import Optional, Union
from sqlmodel import SQLModel

class Person(SQLModel):
    name: str
    birthdate: Optional[Union[date, str]]
    ....

Description

I want to store information about some people in a MySQL database. Due to the nature of the information, birth dates can be full dates (1940-05-02), month and year (1932-07) or years only (1965). I searched the pydantic documentation and it says to use Unions to accept multiple data types. However, when I try to do this sqlmodel raises the error TypeError: issubclass() arg 1 must be a class. I know the issue comes from union because if I remove it then the code works just fine.

Operating System

Windows

Operating System Details

No response

SQLModel Version

0.0.6

Python Version

3.10.2

Additional Context

No response

Maypher avatar Apr 23 '22 23:04 Maypher

Looks like a duplicate of #67, isn't it?

nidico avatar Apr 24 '22 21:04 nidico