[Sqlalchemy-tickets] Issue #4297: Supporting Tests with Rollbacks fails (zzzeek/sqlalchemy)
Brought to you by:
zzzeek
From: marderko <iss...@bi...> - 2018-07-02 14:01:48
|
New issue 4297: Supporting Tests with Rollbacks fails https://bitbucket.org/zzzeek/sqlalchemy/issues/4297/supporting-tests-with-rollbacks-fails marderko: Founded bug in "Transactions and Connection Management" documentation http://docs.sqlalchemy.org/en/latest/orm/session_transaction.html section "Supporting Tests with Rollbacks". There is: ``` # then each time that SAVEPOINT ends, reopen it @event.listens_for(self.session, "after_transaction_end") def restart_savepoint(session, transaction): if transaction.nested and not transaction._parent.nested: # ensure that state is expired the way # session.commit() at the top level normally does # (optional step) session.expire_all() session.begin_nested() ``` I think the if condition is not correct and the right condition is: ``` if transaction.nested and not session.transaction.nested: ``` Explanation: There are constructed some transaction path (or tree) which have `session.transaction` in the end (tree leaf) and `session.transaction._parent._parent....._parent` in the start (tree root) and variable transaction from `restart_savepoint` is the start point (tree leaf). I think the second condition wants to restrict maximal length of path (or tree depth) to 2. But the condition is for path start and `session.begin_nested()` begins nested transaction in the end - so I change the condition also for the path end. I attached failing example with two factories (second has first as subfactory) and simple parametrized test. It is really slow and it fails for tests number > 919 because of maximal recursion depth. After condition change it is really quickly and no fail in any test. |