You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I used the GitHub search to find a similar question 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
fromtypingimportCallable, OptionalfromsqlmodelimportField, SQLModelprint("start")
classBaseTool(SQLModel, table=True):
id: Optional[int] =Field(default=None, primary_key=True)
name: str=Field(index=True)
description: stricon: Optional[str]
# JSON schema of argumentsargs: strprint("middle")
classTool(BaseTool):
"""Tool for use in-memory, includes the tool function. Should not be persisted directly to the DB"""func: Callableprint("end")
Description
run python test.py or python -m test
You should get this output
start
middle
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/root/c2/toddleragi/backend/agi/types/tool.py", line 16, in <module>
class Tool(BaseTool):
File "/root/micromamba/envs/agi/lib/python3.11/site-packages/sqlmodel/main.py", line 293, in __new__
col = get_column_from_field(v)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/micromamba/envs/agi/lib/python3.11/site-packages/sqlmodel/main.py", line 421, in get_column_from_field
sa_type = get_sqlachemy_type(field)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/micromamba/envs/agi/lib/python3.11/site-packages/sqlmodel/main.py", line 375, in get_sqlachemy_type
if issubclass(field.type_, str):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: issubclass() arg 1 must be a class
The problem is that the Callable type should be allowed in a model, as it is in Pydantic, just not persisted to the database. I looked at various suggestions for how to do that, and #147 recommended adding a subclass (Tool from BaseTool) that has the private field, and then casting the instance to the superclass when persisting to a DB. However, the error here happens when initializing the model definition, not when trying to save the model. It is likely that #472 (a small change that adds support for Pydantic PrivateAttributes) might be able to help fix this
Operating System
Linux
Operating System Details
Ubuntu 22.04.1 LTS, Linux 5.15.0-25-generic #25-Ubuntu SMP x86_64 GNU/Linux
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
First Check
Commit to Help
Example Code
Description
python test.py
orpython -m test
The problem is that the Callable type should be allowed in a model, as it is in Pydantic, just not persisted to the database. I looked at various suggestions for how to do that, and #147 recommended adding a subclass (
Tool
fromBaseTool
) that has the private field, and then casting the instance to the superclass when persisting to a DB. However, the error here happens when initializing the model definition, not when trying to save the model. It is likely that #472 (a small change that adds support for PydanticPrivateAttribute
s) might be able to help fix thisOperating System
Linux
Operating System Details
Ubuntu 22.04.1 LTS
,Linux 5.15.0-25-generic #25-Ubuntu SMP x86_64 GNU/Linux
SQLModel Version
0.0.8
Python Version
Python 3.11.3
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions