Set all attributes of transaction before connecting to the database

The connection to the database may fail and thus stop and rollback may be
called. All the attributes must be set to avoid to raise another AttributeError
exception.

Closes #15022
(grafted from 654923a8085d4804dd217e487c80085c53eb470b)

--HG--
branch : 8.0
This commit is contained in:
Cédric Krier
2026-08-17 17:32:55 +02:00
parent c4d1f2ce4b
commit ad81e44df6
+6 -6
View File
@@ -187,13 +187,7 @@ class Transaction(object):
# it is strictly before all transactions started after
# but it may be also before transactions started before
self.started_at = self.monotonic_time()
if not database_name:
database = backend.Database().connect()
else:
database = backend.Database(database_name).connect()
Flavor.set(backend.Database.flavor)
self.user = user
self.database = database
self.readonly = readonly
self.context = ImmutableDict(context or {})
self.create_records = defaultdict(list)
@@ -206,6 +200,12 @@ class Transaction(object):
self.counter = 0
self._datamanagers = []
if not database_name:
database = backend.Database().connect()
else:
database = backend.Database(database_name).connect()
Flavor.set(backend.Database.flavor)
self.database = database
self.connection = database.get_connection(readonly=readonly,
autocommit=autocommit, statement_timeout=timeout)
count = 0