Кусок кода:
def get(arg): attributes['__table_args__'] = {'extend_existing': True, # allows create same objects at one runtime 'prefixes': ["TEMPORARY"]} # always creating temporary table return type(result.name, (Base,), attributes) # returns new class with Properties of Object instance
Далее делаю так:
>>> from app import get, engine >>> from sqlalchemy.schema import CreateTable >>> sim = get('sim_number') >>> sim = get('sim_number') # допустим, понадобилось создать ещё один экземпляр /usr/local/lib/python3.4/dist-packages/sqlalchemy/ext/declarative/clsregistry.py:167: SAWarning: This declarative base already contains a class with the same class name and module name as bill_classes.sim_number, and will be replaced in the string-lookup table. existing.add_item(cls) Traceback (most recent call last): File "/usr/lib/python3.4/code.py", line 90, in runcode exec(code, self.locals) File "<input>", line 1, in <module> File "/media/spicin/7EB7608F698AE718/beeapi/bill_classes.py", line 139, in get return type(result.name, (Base,), attributes) # returns new class with Properties of Object instance File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/ext/declarative/api.py", line 55, in __init__ _as_declarative(cls, classname, cls.__dict__) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/ext/declarative/base.py", line 254, in _as_declarative **table_kw) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/schema.py", line 396, in __new__ table._init_existing(*args, **kw) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/schema.py", line 548, in _init_existing self._extra_kwargs(**kwargs) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/schema.py", line 552, in _extra_kwargs self._validate_dialect_kwargs(kwargs) File "/usr/local/lib/python3.4/dist-packages/sqlalchemy/sql/base.py", line 282, in _validate_dialect_kwargs "named <dialectname>_<argument>, got '%s'" % k) TypeError: Additional arguments should be named <dialectname>_<argument>, got 'prefixes'
Почему при первом создании экземпляра класса всё ок, при втором и последующих - ошибка?