From 6da3370ebbeb8f1c880c06cc91b43677eab86bad Mon Sep 17 00:00:00 2001 From: Majda EL MARIOULI Date: Fri, 8 Nov 2024 17:00:39 -0500 Subject: [PATCH 1/2] TA#70855 [16.0][FIX] base_attachment_object_storage --- .../models/ir_attachment.py | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/base_attachment_object_storage/models/ir_attachment.py b/base_attachment_object_storage/models/ir_attachment.py index e8b17f54..32e66eef 100644 --- a/base_attachment_object_storage/models/ir_attachment.py +++ b/base_attachment_object_storage/models/ir_attachment.py @@ -10,9 +10,10 @@ import psycopg2 import odoo -from odoo import _, api, exceptions, models +from odoo import _, api, exceptions, models, current_context from odoo.osv.expression import AND, OR, normalize_domain from odoo.tools.safe_eval import const_eval +from odoo.modules.registry import Registry from .strtobool import strtobool @@ -260,22 +261,25 @@ def do_in_new_env(self, new_cr=False): Using a new Odoo Environment thus a new PG transaction. """ - with api.Environment.manage(): - if new_cr: - registry = odoo.modules.registry.Registry.new(self.env.cr.dbname) - with closing(registry.cursor()) as cr: - try: - yield self.env(cr=cr) - except Exception: - cr.rollback() - raise - else: - # disable pylint error because this is a valid commit, - # we are in a new env - cr.commit() # pylint: disable=invalid-commit - else: - # make a copy - yield self.env() + ctx = current_context() + env_ctx = { + 'db': self.env.cr.dbname, + } + if new_cr: + registry = Registry(env_ctx['db']) + with closing(registry.cursor()) as cr: + try: + yield self.env(cr=cr) + except Exception: + cr.rollback() + raise + else: + # disable pylint error because this is a valid commit, + # we are in a new env + cr.commit() # pylint: disable=invalid-commit + else: + # make a copy + yield self.env() def _move_attachment_to_store(self): self.ensure_one() From f33444f82e422861d14678b2c4a80eb19a4391c4 Mon Sep 17 00:00:00 2001 From: Majda EL MARIOULI Date: Fri, 8 Nov 2024 17:17:58 -0500 Subject: [PATCH 2/2] TA#70855 [16.0][FIX] base_attachment_object_storage --- base_attachment_object_storage/models/ir_attachment.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/base_attachment_object_storage/models/ir_attachment.py b/base_attachment_object_storage/models/ir_attachment.py index 32e66eef..982f3e0f 100644 --- a/base_attachment_object_storage/models/ir_attachment.py +++ b/base_attachment_object_storage/models/ir_attachment.py @@ -10,7 +10,7 @@ import psycopg2 import odoo -from odoo import _, api, exceptions, models, current_context +from odoo import _, api, exceptions, models from odoo.osv.expression import AND, OR, normalize_domain from odoo.tools.safe_eval import const_eval from odoo.modules.registry import Registry @@ -261,12 +261,8 @@ def do_in_new_env(self, new_cr=False): Using a new Odoo Environment thus a new PG transaction. """ - ctx = current_context() - env_ctx = { - 'db': self.env.cr.dbname, - } if new_cr: - registry = Registry(env_ctx['db']) + registry = Registry.new(self.env.cr.dbname) with closing(registry.cursor()) as cr: try: yield self.env(cr=cr)