|
12 | 12 | from psycopg2 import OperationalError, errorcodes |
13 | 13 | from werkzeug.exceptions import BadRequest, Forbidden |
14 | 14 |
|
15 | | -from odoo import SUPERUSER_ID, _, api, http, registry, tools |
| 15 | +from odoo import SUPERUSER_ID, _, api, http, tools |
16 | 16 | from odoo.service.model import PG_CONCURRENCY_ERRORS_TO_RETRY |
17 | 17 | from odoo.tools import config |
18 | 18 |
|
@@ -149,8 +149,7 @@ def _enqueue_dependent_jobs(cls, env, job): |
149 | 149 | def _runjob(cls, env: api.Environment, job: Job) -> None: |
150 | 150 | def retry_postpone(job, message, seconds=None): |
151 | 151 | job.env.clear() |
152 | | - with registry(job.env.cr.dbname).cursor() as new_cr: |
153 | | - job.env = api.Environment(new_cr, SUPERUSER_ID, {}) |
| 152 | + with job.in_temporary_env(): |
154 | 153 | job.postpone(result=message, seconds=seconds) |
155 | 154 | job.set_pending(reset_retry=False) |
156 | 155 | job.store() |
@@ -194,8 +193,7 @@ def retry_postpone(job, message, seconds=None): |
194 | 193 | traceback_txt = buff.getvalue() |
195 | 194 | _logger.error(traceback_txt) |
196 | 195 | job.env.clear() |
197 | | - with registry(job.env.cr.dbname).cursor() as new_cr: |
198 | | - job.env = job.env(cr=new_cr) |
| 196 | + with job.in_temporary_env(): |
199 | 197 | vals = cls._get_failure_values(job, traceback_txt, orig_exception) |
200 | 198 | job.set_failed(**vals) |
201 | 199 | job.store() |
|
0 commit comments