Skip to content

Commit e5c31f5

Browse files
aj-fuentescawo-odoo
andcommitted
[FIX] util/records: skip wrong views in edit_view
Avoid failing an upgrade when adapting domains in a broken view. Views that are already broken should be skipped. We skip here only non closing tag errors. More cases could be added once we detect them. upg-1154528 upg-1155580 Part of odoo/upgrade#5307 Signed-off-by: Alvaro Fuentes Suarez (afu) <[email protected]> Co-authored-by: "Carsten Wolff (cawo)" <[email protected]>
1 parent c7c95cf commit e5c31f5

File tree

1 file changed

+45
-36
lines changed

1 file changed

+45
-36
lines changed

src/util/domains.py

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import logging
44
import re
55

6+
import lxml
7+
68
try:
79
from contextlib import suppress
810
except ImportError:
@@ -310,42 +312,49 @@ def adapt_domains(cr, model, old, new, adapter=None, skip_inherit=(), force_adap
310312
cr.execute("SELECT id, model FROM ir_ui_view WHERE {} ~ %s".format(arch_db), [match_old])
311313
for view_id, view_model in cr.fetchall():
312314
# Note: active=None is important to not reactivate views!
313-
with suppress(_Skip), edit_view(cr, view_id=view_id, active=None) as view:
314-
modified = False
315-
for node in view.xpath(
316-
"//filter[contains(@domain, '{0}')]|//field[contains(@filter_domain, '{0}')]".format(old)
317-
):
318-
attr = "domain" if "domain" in node.attrib else "filter_domain"
319-
domain = _adapt_one_domain(
320-
cr, target_model, old, new, view_model, node.get(attr), adapter=adapter, force_adapt=force_adapt
321-
)
322-
if domain:
323-
node.set(attr, unicode(domain))
324-
modified = True
325-
326-
for node in view.xpath("//field[contains(@domain, '{0}')]".format(old)):
327-
# as <fields> can happen in sub-views, we should deternine the actual model the field belongs to
328-
path = list(reversed([p.get("name") for p in node.iterancestors("field")])) + [node.get("name")]
329-
field_model = _model_of_path(cr, view_model, path)
330-
if not field_model:
331-
continue
332-
333-
domain = _adapt_one_domain(
334-
cr,
335-
target_model,
336-
old,
337-
new,
338-
field_model,
339-
node.get("domain"),
340-
adapter=adapter,
341-
force_adapt=force_adapt,
342-
)
343-
if domain:
344-
node.set("domain", unicode(domain))
345-
modified = True
346-
347-
if not modified:
348-
raise _Skip
315+
try:
316+
with suppress(_Skip), edit_view(cr, view_id=view_id, active=None) as view:
317+
modified = False
318+
for node in view.xpath(
319+
"//filter[contains(@domain, '{0}')]|//field[contains(@filter_domain, '{0}')]".format(old)
320+
):
321+
attr = "domain" if "domain" in node.attrib else "filter_domain"
322+
domain = _adapt_one_domain(
323+
cr, target_model, old, new, view_model, node.get(attr), adapter=adapter, force_adapt=force_adapt
324+
)
325+
if domain:
326+
node.set(attr, unicode(domain))
327+
modified = True
328+
329+
for node in view.xpath("//field[contains(@domain, '{0}')]".format(old)):
330+
# as <fields> can happen in sub-views, we should deternine the actual model the field belongs to
331+
path = list(reversed([p.get("name") for p in node.iterancestors("field")])) + [node.get("name")]
332+
field_model = _model_of_path(cr, view_model, path)
333+
if not field_model:
334+
continue
335+
336+
domain = _adapt_one_domain(
337+
cr,
338+
target_model,
339+
old,
340+
new,
341+
field_model,
342+
node.get("domain"),
343+
adapter=adapter,
344+
force_adapt=force_adapt,
345+
)
346+
if domain:
347+
node.set("domain", unicode(domain))
348+
modified = True
349+
350+
if not modified:
351+
raise _Skip
352+
except lxml.etree.XMLSyntaxError as e:
353+
if e.msg.startswith("Opening and ending tag mismatch"):
354+
# this view is already wrong, we don't change it
355+
_logger.warning("Skipping domain adpatation for invalid view (id=%s):\n%s", view_id, e.msg)
356+
continue
357+
raise
349358

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

0 commit comments

Comments
 (0)