[Sqlalchemy-tickets] Issue #3015: DELETEs executed twice when using history_meta and subclassing mo
Brought to you by:
zzzeek
From: matt c. <iss...@bi...> - 2014-04-05 01:57:28
|
New issue 3015: DELETEs executed twice when using history_meta and subclassing models https://bitbucket.org/zzzeek/sqlalchemy/issue/3015/deletes-executed-twice-when-using matt chisholm: When using history_meta and also subclassing from model classes (which we do in order to add additional query parameters in our API), SQLAlchemy 0.9.4 raises an error about the number of rows that were deleted not matching the number of rows intended to be deleted. This bug is new in 0.9.4, it does not occur in 0.9.3 or 0.9.2. Attached is a minimal test case. There is also a hack in here which fixes another bug, the `SubclassEquivalenceMixIn`. If you remove that from the base classes for `APIBar`, you can see why we are using that mix-in. Here is the traceback: ``` 2014-04-04 18:55:38,671 INFO sqlalchemy.engine.base.Engine DELETE FROM foo_bar WHERE foo_bar.foo_id = %(foo_id)s AND foo_bar.bar_id = %(bar_id)s 2014-04-04 18:55:38,671 INFO sqlalchemy.engine.base.Engine {'foo_id': 1, 'bar_id': 1} 2014-04-04 18:55:38,672 INFO sqlalchemy.engine.base.Engine DELETE FROM foo_bar WHERE foo_bar.foo_id = %(foo_id)s AND foo_bar.bar_id = %(bar_id)s 2014-04-04 18:55:38,672 INFO sqlalchemy.engine.base.Engine {'foo_id': 1, 'bar_id': 1} 2014-04-04 18:55:38,672 INFO sqlalchemy.engine.base.Engine ROLLBACK Traceback (most recent call last): File "sqlalchemy-delete-bug.py", line 100, in <module> db.session.commit() File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/scoping.py", line 149, in do return getattr(self.registry(), name)(*args, **kwargs) File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 765, in commit self.transaction.commit() File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 370, in commit self._prepare_impl() File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 350, in _prepare_impl self.session.flush() File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1903, in flush self._flush(objects) File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 2021, in _flush transaction.rollback(_capture_exception=True) File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 57, in __exit__ compat.reraise(exc_type, exc_value, exc_tb) File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 1985, in _flush flush_context.execute() File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 370, in execute rec.execute(self) File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/unitofwork.py", line 479, in execute self.dependency_processor.process_saves(uow, states) File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/dependency.py", line 1083, in process_saves secondary_update, secondary_delete) File "/Users/matt/.virtualenvs/sqlalchemy-delete-bug/lib/python2.7/site-packages/sqlalchemy/orm/dependency.py", line 1104, in _run_crud result.rowcount) sqlalchemy.orm.exc.StaleDataError: DELETE statement on table 'foo_bar' expected to delete 1 row(s); Only 0 were matched. ``` I would not be the least bit surprised if either this code or flask-sqlalchemy were just doing something horribly stupid. Responsible: zzzeek |