Skip to content

Commit c077e5b

Browse files
committed
[FIX] util.adapt_domains: don't update unmodified views
The `util.edit_view` contextmanager always write back the view, even if it hasn't been modified. This cause an issue with the saas-16.1 script that remove the `__last_update` field on all model as it is done using multi processes. If any view contains the `__last_update` field, as multiple processes try to modify this view, a `psycopg2.errors.SerializationFailure` exception is raised. tgb-881 Part of odoo/upgrade#5160 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 9e617e3 commit c077e5b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/util/domains.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
import logging
44
import re
55

6+
try:
7+
from contextlib import suppress
8+
except ImportError:
9+
# python2 code, use the openerp vendor
10+
from openerp.tools.misc import ignore as suppress
11+
612
try:
713
from html import unescape
814
except ImportError:
@@ -35,6 +41,10 @@
3541
DomainField = collections.namedtuple("DomainField", "table domain_column model_select")
3642

3743

44+
class _Skip(Exception):
45+
pass
46+
47+
3848
def _get_domain_fields(cr):
3949
# haaa, if only we had a `fields.Domain`, we would just have to get all the domains from `ir_model_fields`
4050
# Meanwile, we have to enumerate them explicitly
@@ -300,7 +310,8 @@ def adapt_domains(cr, model, old, new, adapter=None, skip_inherit=(), force_adap
300310
cr.execute("SELECT id, model FROM ir_ui_view WHERE {} ~ %s".format(arch_db), [match_old])
301311
for view_id, view_model in cr.fetchall():
302312
# Note: active=None is important to not reactivate views!
303-
with edit_view(cr, view_id=view_id, active=None) as view:
313+
with suppress(_Skip), edit_view(cr, view_id=view_id, active=None) as view:
314+
modified = False
304315
for node in view.xpath(
305316
"//filter[contains(@domain, '{0}')]|//field[contains(@filter_domain, '{0}')]".format(old)
306317
):
@@ -310,6 +321,7 @@ def adapt_domains(cr, model, old, new, adapter=None, skip_inherit=(), force_adap
310321
)
311322
if domain:
312323
node.set(attr, unicode(domain))
324+
modified = True
313325

314326
for node in view.xpath("//field[contains(@domain, '{0}')]".format(old)):
315327
# as <fields> can happen in sub-views, we should deternine the actual model the field belongs to
@@ -330,6 +342,10 @@ def adapt_domains(cr, model, old, new, adapter=None, skip_inherit=(), force_adap
330342
)
331343
if domain:
332344
node.set("domain", unicode(domain))
345+
modified = True
346+
347+
if not modified:
348+
raise _Skip
333349

334350
# adapt domain in dashboards.
335351
# NOTE: does not filter on model at dashboard selection for handle dotted domains

0 commit comments

Comments
 (0)