ArgumentError using Mixin classes #1332
Unanswered
filipposantovito
asked this question in
Questions
Replies: 1 comment 1 reply
-
#743 |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
the code above throws an exception while it is supposed to work. This is the stacktrace:
(venv) filippo@dev101:~/tmp/sqlmodel_mixin$ python main.py
Traceback (most recent call last):
File "/home/filippo/tmp/sqlmodel_mixin/main.py", line 32, in
class MyModel2( TimeStampMixin, table=True):
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlmodel/main.py", line 641, in init
DeclarativeMeta.init(cls, classname, bases, dict_, **kw)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/orm/decl_api.py", line 198, in init
as_declarative(reg, cls, dict)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 244, in _as_declarative
return MapperConfig.setup_mapping(registry, cls, dict, None, {})
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 325, in setup_mapping
return _ClassScanMapperConfig(
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 576, in init
self._setup_table(table)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/orm/decl_base.py", line 1757, in _setup_table
table_cls(
File "", line 2, in new
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 430, in new
return cls._new(*args, **kw)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 484, in _new
with util.safe_reraise():
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/util/langhelpers.py", line 146, in exit
raise exc_value.with_traceback(exc_tb)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 480, in _new
table.init(name, metadata, *args, _no_init=False, **kw)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 874, in init
self._init_items(
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 234, in _init_items
spwd(self, **kw)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/sql/base.py", line 1324, in _set_parent_with_dispatch
self._set_parent(parent, **kw)
File "/home/filippo/tmp/sqlmodel_mixin/venv/lib/python3.10/site-packages/sqlalchemy/sql/schema.py", line 2337, in _set_parent
raise exc.ArgumentError(
sqlalchemy.exc.ArgumentError: Column object 'created_at' already assigned to Table 'mymodel'
It works using the mixin class just in one SqlModel model but this is not the intended use of a mixin class
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.24
Python Version
3.10.12
Additional Context
(venv) filippo@dev101:~/tmp/sqlmodel_mixin$ pip freeze
annotated-types==0.7.0
greenlet==3.1.1
pydantic==2.10.6
pydantic_core==2.27.2
SQLAlchemy==2.0.39
sqlmodel==0.0.24
typing_extensions==4.13.0
Beta Was this translation helpful? Give feedback.
All reactions