Title: TypeError: issubclass() arg 1 must be a class when having a field with a complex type · Issue #67 · fastapi/sqlmodel · GitHub
Open Graph Title: TypeError: issubclass() arg 1 must be a class when having a field with a complex type · Issue #67 · fastapi/sqlmodel
X Title: TypeError: issubclass() arg 1 must be a class when having a field with a complex type · Issue #67 · fastapi/sqlmodel
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...
Open Graph 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...
X 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 searc...
Opengraph URL: https://github.com/fastapi/sqlmodel/issues/67
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeError: issubclass() arg 1 must be a class when having a field with a complex type","articleBody":"### First Check\r\n\r\n- [X] I added a very descriptive title to this issue.\r\n- [X] I used the GitHub search to find a similar issue and didn't find it.\r\n- [X] I searched the SQLModel documentation, with the integrated search.\r\n- [X] I already searched in Google \"How to X in SQLModel\" and didn't find any information.\r\n- [X] I already read and followed all the tutorial in the docs and didn't find an answer.\r\n- [X] I already checked if it is not related to SQLModel but to [Pydantic](https://github.com/samuelcolvin/pydantic).\r\n- [X] I already checked if it is not related to SQLModel but to [SQLAlchemy](https://github.com/sqlalchemy/sqlalchemy).\r\n\r\n### Commit to Help\r\n\r\n- [X] I commit to help with one of those options 👆\r\n\r\n### Example Code\r\n\r\n```python\r\nfrom datetime import datetime\r\nfrom typing import Optional, List, Tuple, Dict, Union\r\nfrom sqlmodel import Field, SQLModel, create_engine\r\n\r\nclass SemanticSearch(SQLModel, table=True):\r\n id: Optional[int] = Field(default=None, primary_key=True)\r\n id_user: int\r\n date_time: datetime\r\n query: str\r\n clean_query: str\r\n semantic_search_result: List[Tuple[int, Dict[str, Union[str, int, float]]]]\r\n\r\n## sqlite\r\nsqlite_file_name = \"database.db\"\r\nsqlite_url = f\"sqlite:///{sqlite_file_name}\"\r\n\r\nengine = create_engine(sqlite_url, echo=True)\r\n\r\nSQLModel.metadata.create_all(engine)\r\n```\r\n\r\n\r\n### Description\r\n\r\nI would like to create a `semantic_search` table in the `database.db` sqlite database with the 6 fields specified.\r\n\r\nThe last field `semantic_search_result` with `List[Tuple[int, Dict[str, Union[str, int, float]]]]` type seems to cause the error.\r\n\r\n`semantic_search_result` looks like this for example:\r\n```\r\n[\r\n (0, { \"acquisCode\": str, \"code\": str, \"level\": int, \"title\": str, \"similarity_score\": float}),\r\n (1, { \"acquisCode\": str, \"code\": str, \"level\": int, \"title\": str, \"similarity_score\": float}),\r\n (2, { \"acquisCode\": str, \"code\": str, \"level\": int, \"title\": str, \"similarity_score\": float})\r\n]\r\n```\r\nWhen running the code I got the following error:\r\n```\r\nTraceback (most recent call last):\r\n File \"/home/matthieu/Code/Python/fastapi-graphql/test_SQLModel.py\", line 6, in \u003cmodule>\r\n class SemanticSearch(SQLModel, table=True):\r\n File \"/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlmodel/main.py\", line 292, in __new__\r\n col = get_column_from_field(v)\r\n File \"/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlmodel/main.py\", line 415, in get_column_from_field\r\n sa_type = get_sqlachemy_type(field)\r\n File \"/home/matthieu/anaconda3/envs/sts-transformers-gpu-fresh/lib/python3.8/site-packages/sqlmodel/main.py\", line 373, in get_sqlachemy_type\r\n if issubclass(field.type_, str):\r\nTypeError: issubclass() arg 1 must be a class\r\n```\r\nI got the same error if I tried to define a subclass of the `typing_extensions.TypedDict` class:\r\n```\r\nclass SemanticSearchDict(TypedDict):\r\n acquis_code: str\r\n code: str\r\n level: int\r\n title: str\r\n similarity_score: float\r\n\r\nclass SemanticSearch(SQLModel, table=True):\r\n id: Optional[int] = Field(default=None, primary_key=True)\r\n id_user: int\r\n date_time: datetime\r\n query: str\r\n clean_query: str\r\n semantic_search_result: List[Tuple[int, SemanticSearchDict]]\r\n```\r\nI couldn't find a solution but #57 seems to have the same problem since having the same error.\r\n\r\n### Operating System\r\n\r\nLinux\r\n\r\n### Operating System Details\r\n\r\nUbuntu 18.04 LTS\r\n\r\n### SQLModel Version\r\n\r\n0.0.4\r\n\r\n### Python Version\r\n\r\n3.8.8\r\n\r\n### Additional Context\r\n\r\n_No response_","author":{"url":"https://github.com/Matthieu-Tinycoaching","@type":"Person","name":"Matthieu-Tinycoaching"},"datePublished":"2021-09-01T11:56:18Z","url":"https://github.com/fastapi/sqlmodel/issues/67"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:a6a89a1a-f8a7-b745-3a90-66f91daccfba |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | ACEE:3BE529:7720FF:A38598:6AFDEF78 |
| html-safe-nonce | 11871150704a1722445df182f5f962a42a7e84a17be3ed7360be2dc483fe23cb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQ0VFOjNCRTUyOTo3NzIwRkY6QTM4NTk4OjZBRkRFRjc4IiwidmlzaXRvcl9pZCI6IjIxNTkwNTQzMDAyODAzODU0MDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e8f01aa3982a4a9572c3d91df1ad17732dbff10849f677c09cd857405874403d |
| hovercard-subject-tag | issue:985059294 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/fastapi/sqlmodel/67/issue_layout |
| twitter:image | https://opengraph.githubassets.com/610b14eba1585cac32bcf0a9c7a5c72f36fea0d8d1c00f5130123884e065ada9/fastapi/sqlmodel/issues/67 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/610b14eba1585cac32bcf0a9c7a5c72f36fea0d8d1c00f5130123884e065ada9/fastapi/sqlmodel/issues/67 |
| og:image:alt | 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... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Matthieu-Tinycoaching |
| hostname | github.com |
| expected-hostname | github.com |
| None | dd812ec581ecac95855f5ec917ef9827506c39a9da1443f43ddb4179a46471eb |
| turbo-cache-control | no-preview |
| go-import | github.com/fastapi/sqlmodel git https://github.com/fastapi/sqlmodel.git |
| octolytics-dimension-user_id | 156354296 |
| octolytics-dimension-user_login | fastapi |
| octolytics-dimension-repository_id | 399495186 |
| octolytics-dimension-repository_nwo | fastapi/sqlmodel |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 399495186 |
| octolytics-dimension-repository_network_root_nwo | fastapi/sqlmodel |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 32ac708bac264dafdc28e10ff49b4d137f0c34a7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width