From 47dd11660dbc2c6072404bba3279367a7263c1da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 17 Aug 2026 17:32:55 +0200 Subject: [PATCH] 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 --- trytond/trytond/transaction.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/trytond/trytond/transaction.py b/trytond/trytond/transaction.py index 47b828e3fc..e6baaeb40c 100644 --- a/trytond/trytond/transaction.py +++ b/trytond/trytond/transaction.py @@ -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