summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOlly Cope <olly@ollycope.com>2022-11-03 09:36:45 +0000
committerOlly Cope <olly@ollycope.com>2022-11-03 09:36:45 +0000
commitfc76b2a282662f4c44cad49e92ed56274be47a1d (patch)
tree2b240c19c59b46d586a951d5491108033cbede8e
parente4b7a5a0e18d45fa1a07a2a0983eef25c304d391 (diff)
downloadyoyo-fc76b2a282662f4c44cad49e92ed56274be47a1d.tar.gz
postgresql backend: move nested transaction warning into `begin` method
Triggering a UserWarning in `transaction` is too early. Nested transactions should be detected by ``DatabaseBackend.transaction`` and converted to savepoints. We should only warn if a BEGIN statement is issued.
-rw-r--r--yoyo/backends/core/postgresql.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/yoyo/backends/core/postgresql.py b/yoyo/backends/core/postgresql.py
index 17e9963..09d0f06 100644
--- a/yoyo/backends/core/postgresql.py
+++ b/yoyo/backends/core/postgresql.py
@@ -64,16 +64,6 @@ class PostgresqlBackend(DatabaseBackend):
connection.autocommit = autocommit
return connection
- def transaction(self, rollback_on_exit=False):
-
- if self.connection.info.transaction_status != self.TRANSACTION_STATUS_IDLE:
- warnings.warn(
- "Nested transaction requested; "
- "this will raise an exception in some "
- "PostgreSQL-compatible databases"
- )
- return super().transaction(rollback_on_exit=rollback_on_exit)
-
@contextmanager
def disable_transactions(self):
with super(PostgresqlBackend, self).disable_transactions():
@@ -101,6 +91,15 @@ class PostgresqlBackend(DatabaseBackend):
self.execute("ROLLBACK")
super().rollback()
+ def begin(self):
+ if self.connection.info.transaction_status != self.TRANSACTION_STATUS_IDLE:
+ warnings.warn(
+ "Nested transaction requested; "
+ "this will raise an exception in some "
+ "PostgreSQL-compatible databases"
+ )
+ return super().begin()
+
class PostgresqlPsycopgBackend(PostgresqlBackend):
"""