[REV] base: revert 9f7f1db5add5b8a940e53707091133c0bcadd350

Revert commit
"[FIX] base: clearer message in case of conflict for no_gap sequences"

This commit changed the error returned in case of SQL conflict for no_gap
sequences, wrongly disabling the automatic retry (service/model.py) in case
of such errors.

Also adds a comment in the dedicated test to ensure the behavior is explained
and the automatic retry isn't broken once again by the same kind of change.

closes odoo/odoo#59928

X-original-commit: 811cd40fe427c28f9eb244f78ae23c4d3fb42cc8
Signed-off-by: Victor Feyens (vfe) <vfe@odoo.com>
This commit is contained in:
Victor Feyens
2020-10-14 00:18:35 +00:00
parent ad7ef0800d
commit 4841e5c690
3 changed files with 6 additions and 18 deletions
-8
View File
@@ -23895,14 +23895,6 @@ msgid ""
"%s"
msgstr ""
#. module: base
#: code:addons/base/models/ir_sequence.py:0
#, python-format
msgid ""
"This transaction wasn't executed because another transaction is already "
"using the same no-gap sequence. Please try again later."
msgstr ""
#. module: base
#: model:ir.model.fields,field_description:base.field_res_lang__thousands_sep
msgid "Thousands Separator"
+2 -8
View File
@@ -53,14 +53,8 @@ def _select_nextval(cr, seq_name):
def _update_nogap(self, number_increment):
number_next = self.number_next
try:
self._cr.execute("SELECT number_next FROM %s WHERE id=%%s FOR UPDATE NOWAIT" % self._table, [self.id])
self._cr.execute("UPDATE %s SET number_next=number_next+%%s WHERE id=%%s " % self._table, (number_increment, self.id))
except OperationalError as e:
if e.pgcode == errorcodes.LOCK_NOT_AVAILABLE:
raise UserError(_("This transaction wasn't executed because another transaction is already using the same no-gap sequence. Please try again later."))
else:
raise
self._cr.execute("SELECT number_next FROM %s WHERE id=%%s FOR UPDATE NOWAIT" % self._table, [self.id])
self._cr.execute("UPDATE %s SET number_next=number_next+%%s WHERE id=%%s " % self._table, (number_increment, self.id))
self.invalidate_cache(['number_next'], [self.id])
return number_next
+4 -2
View File
@@ -7,7 +7,6 @@ import psycopg2
import psycopg2.errorcodes
import odoo
from odoo.exceptions import UserError
from odoo.tests import common
from odoo.tests.common import BaseCase
@@ -93,10 +92,13 @@ class TestIrSequenceNoGap(BaseCase):
with environment() as env0:
with environment() as env1:
env1.cr._default_log_exceptions = False # Prevent logging a traceback
with self.assertRaises(UserError) as e:
# NOTE: The error has to be an OperationalError
# s.t. the automatic request retry (service/model.py) works.
with self.assertRaises(psycopg2.OperationalError) as e:
n0 = env0['ir.sequence'].next_by_code('test_sequence_type_2')
self.assertTrue(n0)
n1 = env1['ir.sequence'].next_by_code('test_sequence_type_2')
self.assertEqual(e.exception.pgcode, psycopg2.errorcodes.LOCK_NOT_AVAILABLE, msg="postgresql returned an incorrect errcode")
@classmethod
def tearDownClass(cls):