-
-
Notifications
You must be signed in to change notification settings - Fork 752
Closed
Labels
questionFurther information is requestedFurther information is requested
Description
First Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue 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
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
woprandi, elben10, nidico, data-djinn, ChouUn and 9 morethomasleveil
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested