Open Matthieu-Tinycoaching opened 3 years ago
🆙
Up!
different cause it seems, but #121 has a similar error.
same Problem
same problem here!
thank you to the maintainers & contributors of this awesome library!
For anyone who encounters this bug while trying to assign a Literal
type, the workaround that I used was defining a separate class of Enum
instances:
from enum import Enum
class ValidValues:
class FirstField(str, Enum):
FIRST_VAL = 'First val',
SECOND_VAL = 'Second val'
class SecondField(str, Enum):
FIRST_VAL = 'First val',
SECOND_VAL = 'Second val'
# etc..
class MyTable(SQLModel, table=True):
first_field: ValidValues.FirstField
second_field: ValidValues.SecondField
some_str_field: str
# etc...
Any update on this issue?
same happen using UUID4 for id
Its because of the get_sqlachemy_type
function. literals and perhaps dict isnt recognized
you can bypass this using sa_column
for literal types
kind: t.Annotated[t.Literal["resource"])] = Field(
default="resource", sa_column=Column(String)
)
i think dicts need to be typed to json
First Check
Commit to Help
Example Code
Description
I would like to create a
semantic_search
table in thedatabase.db
sqlite database with the 6 fields specified.The last field
semantic_search_result
withList[Tuple[int, Dict[str, Union[str, int, float]]]]
type seems to cause the error.semantic_search_result
looks like this for example:When running the code I got the following error:
I got the same error if I tried to define a subclass of the
typing_extensions.TypedDict
class:I couldn't find a solution but #57 seems to have the same problem since having the same error.
Operating System
Linux
Operating System Details
Ubuntu 18.04 LTS
SQLModel Version
0.0.4
Python Version
3.8.8
Additional Context
No response