First Check
Commit to Help
Example Code
from typing import Optional
from sqlalchemy_continuum import make_versioned
from sqlmodel import Field, Session, SQLModel, create_engine
from sqlmodel.main import default_registry
# setattr(SQLModel, 'registry', default_registry)
make_versioned(user_cls=None)
class Hero(SQLModel, table=True):
__versioned__ = {}
id: Optional[int] = Field(default=None, primary_key=True)
name: str
secret_name: str
age: Optional[int] = None
hero_1 = Hero(name="Deadpond", secret_name="Dive Wilson")
engine = create_engine("sqlite:///database.db")
SQLModel.metadata.create_all(engine)
with Session(engine) as session:
session.add(hero_1)
session.commit()
session.refresh(hero_1)
print(hero_1)
Description
Very basic setup of SQLAlchemy-Continuum doesn't work with SQLModel. Following error raised (see here):
AttributeError: type object 'SQLModel' has no attribute '_decl_class_registry'
SQLModel class misses some expected attribute (registry for SQLAlchemy >= 1.4) from SQLAlchemy's Base. For debugging purposes the attribute can be manually populated (uncomment # setattr(SQLModel, 'registry', default_registry) in the example code) and it helps to proceed to the next error:
<skipped>
File ".../.venv/lib/python3.10/site-packages/sqlmodel/main.py", line 277, in __new__
new_cls = super().__new__(cls, name, bases, dict_used, **config_kwargs)
File "pydantic/main.py", line 228, in pydantic.main.ModelMetaclass.__new__
File "pydantic/fields.py", line 488, in pydantic.fields.ModelField.infer
File "pydantic/fields.py", line 419, in pydantic.fields.ModelField.__init__
File "pydantic/fields.py", line 528, in pydantic.fields.ModelField.prepare
File "pydantic/fields.py", line 552, in pydantic.fields.ModelField._set_default_and_type
File "pydantic/fields.py", line 422, in pydantic.fields.ModelField.get_default
File "pydantic/utils.py", line 652, in pydantic.utils.smart_deepcopy
File ".../.venv/lib/python3.10/site-packages/sqlalchemy/sql/elements.py", line 582, in __bool__
raise TypeError("Boolean value of this clause is not defined")
TypeError: Boolean value of this clause is not defined
Looks like there is some incompatibility with SQLAlchemy's expected behaviour, because this error was thrown just after SQLModel's __new__ method call.
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.10.2
Additional Context
No response
First Check
Commit to Help
Example Code
Description
Very basic setup of SQLAlchemy-Continuum doesn't work with SQLModel. Following error raised (see here):
SQLModelclass misses some expected attribute (registryfor SQLAlchemy >= 1.4) from SQLAlchemy'sBase. For debugging purposes the attribute can be manually populated (uncomment# setattr(SQLModel, 'registry', default_registry)in the example code) and it helps to proceed to the next error:Looks like there is some incompatibility with SQLAlchemy's expected behaviour, because this error was thrown just after SQLModel's
__new__method call.Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.10.2
Additional Context
No response