[Sqlalchemy-tickets] Issue #3996: unincremented version id counter on superclass (zzzeek/sqlalchemy
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2017-05-22 18:31:28
|
New issue 3996: unincremented version id counter on superclass https://bitbucket.org/zzzeek/sqlalchemy/issues/3996/unincremented-version-id-counter-on Michael Bayer: from #3673 ``` #!python from sqlalchemy import * from sqlalchemy import types from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base, declared_attr from sqlalchemy import event from datetime import datetime Base = declarative_base() class Foo(Base): __tablename__ = 'foo' id = Column(types.Integer, primary_key=True) type = Column(types.Unicode(64), nullable=False) bar = Column(types.DateTime(), nullable=False) other = Column(types.Integer) __mapper_args__ = { 'polymorphic_on': u'type', 'polymorphic_identity': u'Foo', 'version_id_col': bar, 'version_id_generator': False } class FooDerived(Foo): __tablename__ = 'foo_derived' id = Column(types.Integer, ForeignKey(u'foo.id'), primary_key=True) other2 = Column(types.Integer) __mapper_args__ = { 'polymorphic_identity': u'FooDerived' } e = create_engine('sqlite:///:memory:', echo='debug') Base.metadata.drop_all(e) Base.metadata.create_all(e) session = Session(e, autocommit=True, autoflush=False, expire_on_commit=False) x = FooDerived() x.bar = datetime(1970, 1, 1) session.add(x) session.flush() x.other2 = 1 session.flush() ``` it tries to update the primary table: ``` #! OperationalError: (sqlite3.OperationalError) near "WHERE": syntax error [SQL: u'UPDATE foo SET WHERE foo.id = ? AND foo.bar = ?'] [parameters: (1, '1970-01-01 00:00:00.000000')] ``` docs: ``` #! We can update our ``User`` object without incrementing the version counter as well; the value of the counter will remain unchanged, and the UPDATE statement will still check against the previous value. This may be useful for schemes where only certain classes of UPDATE are sensitive to concurrency issues:: ``` |