Here are the examples of the python api sqlalchemy.exc.PendingRollbackError taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
3
Source : test_reconnect.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_rollback_on_invalid_savepoint(self):
with self.engine.connect() as conn:
conn.begin()
trans2 = conn.begin_nested()
conn.invalidate()
# this passes silently, as it will often be involved
# in error catching schemes
trans2.rollback()
# still invalid though
with expect_raises(exc.PendingRollbackError):
conn.begin_nested()
def test_no_begin_on_invalid(self):
3
Source : test_reconnect.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_no_begin_on_invalid(self):
with self.engine.connect() as conn:
conn.begin()
conn.invalidate()
with expect_raises(exc.PendingRollbackError):
conn.commit()
def test_invalidate_twice(self):
0
Source : test_reconnect.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_reconnect(self):
with self.engine.connect() as conn:
eq_(conn.execute(select(1)).scalar(), 1)
assert not conn.closed
self.engine.test_shutdown()
_assert_invalidated(conn.execute, select(1))
assert not conn.closed
assert conn.invalidated
assert conn.invalidated
with expect_raises(tsa.exc.PendingRollbackError):
conn.execute(select(1))
conn.rollback()
eq_(conn.execute(select(1)).scalar(), 1)
assert not conn.invalidated
# one more time
self.engine.test_shutdown()
_assert_invalidated(conn.execute, select(1))
assert conn.invalidated
conn.rollback()
eq_(conn.execute(select(1)).scalar(), 1)
assert not conn.invalidated
def test_detach_invalidated(self):
0
Source : test_reconnect.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_with_transaction(self):
with self.engine.connect() as conn:
trans = conn.begin()
assert trans.is_valid
eq_(conn.execute(select(1)).scalar(), 1)
assert not conn.closed
self.engine.test_shutdown()
_assert_invalidated(conn.execute, select(1))
assert not conn.closed
assert conn.invalidated
assert trans.is_active
assert not trans.is_valid
assert_raises_message(
tsa.exc.PendingRollbackError,
"Can't reconnect until invalid transaction is rolled back",
conn.execute,
select(1),
)
assert trans.is_active
assert not trans.is_valid
assert_raises_message(
tsa.exc.PendingRollbackError,
"Can't reconnect until invalid transaction is rolled back",
trans.commit,
)
# becomes inactive
assert not trans.is_active
assert not trans.is_valid
# still asks us to rollback
assert_raises_message(
tsa.exc.PendingRollbackError,
"Can't reconnect until invalid transaction is rolled back",
conn.execute,
select(1),
)
# still asks us..
assert_raises_message(
tsa.exc.PendingRollbackError,
"Can't reconnect until invalid transaction is rolled back",
trans.commit,
)
# still...it's being consistent in what it is asking.
assert_raises_message(
tsa.exc.PendingRollbackError,
"Can't reconnect until invalid transaction is rolled back",
conn.execute,
select(1),
)
# OK!
trans.rollback()
assert not trans.is_active
assert not trans.is_valid
# conn still invalid but we can reconnect
assert conn.invalidated
eq_(conn.execute(select(1)).scalar(), 1)
assert not conn.invalidated
class RecycleTest(fixtures.TestBase):
0
Source : test_transaction.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_rollback_inactive(self):
users = self.tables.users
with testing.db.connect() as conn:
conn.execute(users.insert(), {"user_id": 1, "user_name": "name"})
conn.commit()
conn.execute(users.insert(), {"user_id": 2, "user_name": "name2"})
conn.invalidate()
assert_raises_message(
exc.PendingRollbackError,
"Can't reconnect",
conn.execute,
select(1),
)
conn.rollback()
eq_(
conn.scalar(select(func.count(1)).select_from(users)),
1,
)
def test_rollback_no_begin(self):
0
Source : test_transaction.py
with MIT License
from sqlalchemy
with MIT License
from sqlalchemy
def test_preserve_flush_error(self):
User = self.classes.User
sess, u1 = self._inactive_flushed_session_fixture()
for i in range(5):
assert_raises_message(
sa_exc.PendingRollbackError,
"^This Session's transaction has been "
r"rolled back due to a previous exception "
"during flush. To "
"begin a new transaction with this "
"Session, first issue "
r"Session.rollback\(\). Original exception "
"was:",
sess.commit,
)
sess.rollback()
sess.add(User(id=5, name="some name"))
sess.commit()
def test_no_autobegin_after_explicit_commit(self):