On 05/06/2019 16:41, Mike Bayer wrote:

Which gives me:

$ python sessions_are_weird.py
Traceback (most recent call last):
  File "sessions_are_weird.py", line 40, in <module>
    assert session.query(Event).count() == 0
AssertionError

Whereas after the rollback, I'd expect that count to be zero...

this is not working because of this:

         session.close()

         # test:
         session.rollback()


the session is closed first so rollback() will do nothing.

Yeah, that was my point: That session.close() appears to be the problem. It's a normal and required part of the code under test, but it throws away the SessionTransaction without rolling it back, so by the time the test does session.rollback(), it's doing it on a new SessionTransaction and so has no effect and the assertion fails because there event created is still around...

Put differently, the web app closes the session at the end of its request handling, which seems legit, right?

How come close() doesn't rollback the SessionTransaction if it throws it away?

Chris

--
SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sqlalchemy/806b6413-8537-8813-5c32-1238086300dd%40withers.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to