[Sqlalchemy-tickets] Issue #3839: "FlushError: Over 100 subsequent flushes" when deleting same obje
Brought to you by:
zzzeek
From: Adrian <iss...@bi...> - 2016-10-27 09:21:50
|
New issue 3839: "FlushError: Over 100 subsequent flushes" when deleting same object twice in 1.1 https://bitbucket.org/zzzeek/sqlalchemy/issues/3839/flusherror-over-100-subsequent-flushes Adrian: ```python from sqlalchemy import * from sqlalchemy.orm import * from sqlalchemy.ext.declarative import declarative_base Base = declarative_base() class Foo(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) e = create_engine('sqlite:///', echo=False) Base.metadata.create_all(e) s = Session(e) s.add(Foo()) s.commit() foo = s.query(Foo).first() s.delete(foo) s.flush() s.delete(foo) s.flush() s.commit() ``` With SQLalchemy 1.0: ``` [adrian@blackhole:/tmp/test]> pip install -q 'sqlalchemy<1.1' [adrian@blackhole:/tmp/test]> python satest.py /tmp/test/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py:925: SAWarning: DELETE statement on table 'foo' expected to delete 1 row(s); 0 were matched. Please set confirm_deleted_rows=False within the mapper configuration to prevent this warning. (table.description, expected, rows_matched) ``` With SQLAlchemy 1.1: ``` [adrian@blackhole:/tmp/test]> pip install -Uq sqlalchemy [adrian@blackhole:/tmp/test]> python satest.py Traceback (most recent call last): File "satest.py", line 26, in <module> s.commit() File "/tmp/test/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 874, in commit self.transaction.commit() File "/tmp/test/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 461, in commit self._prepare_impl() File "/tmp/test/lib/python2.7/site-packages/sqlalchemy/orm/session.py", line 444, in _prepare_impl "Over 100 subsequent flushes have occurred within " sqlalchemy.orm.exc.FlushError: Over 100 subsequent flushes have occurred within session.commit() - is an after_flush() hook creating new objects? ``` It looks like the second delete adds the object to `s.deleted` and it stays there forever. It also fails only during `s.commit()`. not during a normal `s.flush()` While it can be considered a bug in my application that I end up deleting the same object twice, I don't think the 1.1 behavior is correct - if it should indeed be an error case instead of just a warning as in 1.0 the error should probably be somewhat clear. |