Hi, I'd really appreciate some assistance with the below issue.
Rolling back sqlalchemy transactions cross-flush currently appears
impossible to me. It’s necessary if you want to issue queries that rely on
the presence of an assigned primary key identifier (adding something to the
session isn’t sufficient to get a primary key assigned).
But if you issue such a query, you’ll either get a query-invoked autoflush
(if autoflush is on), or you’ll have to flush first. And this apparently
seems to changes the scope of what gets rolled back on session.rollback().
It seems to be only the stuff after the flush.
Use case: rolling back on the teardown method of unit tests that require
flushes.
Solution I'm looking for: A way to roll back *all* uncommitted changes
after a savepoint/virtual transaction/some other kind of transactional
wrapper is created in the setUp method of a unittest.TestCase subclass.
Example:
session = sessionmaker()
class MyTest(unittest.TestCase):
def setUp(self):
session.begin_nested()
def tearDown(self):
session.rollback()
def myTest(self):
session.add(object) # now a flush is required because `id` is used below
query = session.query('select id from my_table where id =
{}'.format(object.id))
# Problem: Now `object` will exist even after `tearDown`
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.