Do not retrieve current transaction to fetch model attribute

It is the transaction stored on the instance that must be used and which is set
by the context manager.
This commit is contained in:
Cédric Krier
2025-01-21 18:43:23 +01:00
parent 8072751d7f
commit c91542adfb
+3 -3
View File
@@ -1778,7 +1778,7 @@ class ModelStorage(Model):
kwargs_cache = {}
pysoned_ctx = {}
transaction = Transaction()
transaction = self._transaction
def create_instances(Model, value, cache_key=None):
cache_key = (Model, cache_key)
@@ -1839,11 +1839,11 @@ class ModelStorage(Model):
model2ids = {}
model2cache = {}
# Read the data
with Transaction().set_current_transaction(self._transaction), \
with Transaction().set_current_transaction(transaction), \
self._transaction.set_user(self._user), \
self._transaction.reset_context(), \
self._transaction.set_context(self._context), \
without_check_access() as transaction:
without_check_access():
if (self.id in self._cache and name in self._cache[self.id]
and ffields.keys() <= set(self._cache[self.id]._keys())):
# Use values from cache