First Check
Commit to Help
Example Code
from datetime import datetime
from typing import Optional, List, Tuple, Dict, Union
from sqlmodel import Field, SQLModel, create_engine
class SemanticSearch(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
id_user: int
date_time: datetime
query: str
clean_query: str
semantic_search_result: List[Tuple[int, Dict[str, Union[str, int, float]]]]
## sqlite
sqlite_file_name = "database.db"
sqlite_url = f"sqlite:///{sqlite_file_name}"
engine = create_engine(sqlite_url, echo=True)
SQLModel.metadata.create_all(engine)
Description
I would like to create a semantic_search table in the database.db sqlite database with the 6 fields specified.
The last field semantic_search_result with List[Tuple[int, Dict[str, Union[str, int, float]]]] type seems to cause the error.
semantic_search_result looks like this for example:
[
(0, { "acquisCode": str, "code": str, "level": int, "title": str, "similarity_score": float}),
(1, { "acquisCode": str, "code": str, "level": int, "title": str, "similarity_score": float}),
(2, { "acquisCode": str, "code": str, "level": int, "title": str, "similarity_score": float})
]
When running the code I got the following error:
Traceback (most recent call last):
File "/home/matthieu/Code/Python/fastapi-graphql/test_SQLModel.py", line 6, in <module>
class SemanticSearch(SQLModel, table=True):
File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlmodel/main.py", line 292, in __new__
col = get_column_from_field(v)
File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlmodel/main.py", line 415, in get_column_from_field
sa_type = get_sqlachemy_type(field)
File "/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlmodel/main.py", line 373, in get_sqlachemy_type
if issubclass(field.type_, str):
TypeError: issubclass() arg 1 must be a class
I got the same error if I tried to define a subclass of the typing_extensions.TypedDict class:
class SemanticSearchDict(TypedDict):
acquis_code: str
code: str
level: int
title: str
similarity_score: float
class SemanticSearch(SQLModel, table=True):
id: Optional[int] = Field(default=None, primary_key=True)
id_user: int
date_time: datetime
query: str
clean_query: str
semantic_search_result: List[Tuple[int, SemanticSearchDict]]
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
First Check
Commit to Help
Example Code
Description
I would like to create a
semantic_searchtable in thedatabase.dbsqlite database with the 6 fields specified.The last field
semantic_search_resultwithList[Tuple[int, Dict[str, Union[str, int, float]]]]type seems to cause the error.semantic_search_resultlooks 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.TypedDictclass: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