Skip to content

Commit f234ed4

Browse files
committed
[FIX] base/17.0: skip invalid attrs
Some of the extra attributes' keys that the customer might add to `attrs` are invalid for lxml (due to not being valid for libxml). In these cases, those `attrs` elements cannot be inlined and are best skipped altogether. ``` Traceback (most recent call last): File "/home/odoo/src/odoo/17.0/odoo/service/server.py", line 1302, in preload_registries registry = Registry.new(dbname, update_module=update_module) File "<decorator-gen-16>", line 2, in new File "/home/odoo/src/odoo/17.0/odoo/tools/func.py", line 87, in locked return func(inst, *args, **kwargs) File "/home/odoo/src/odoo/17.0/odoo/modules/registry.py", line 113, in new odoo.modules.load_modules(registry, force_demo, status, update_module) File "/home/odoo/src/odoo/17.0/odoo/modules/loading.py", line 514, in load_modules migrations.migrate_module(package, 'end') File "/home/odoo/src/odoo/17.0/odoo/modules/migration.py", line 240, in migrate_module migrate(self.cr, installed_version) File "/tmp/tmpqxlqi07y/migrations/base/saas~16.5.1.3/end-01-attrs-views.py", line 149, in migrate new_archs = fix_archs(info) File "/tmp/tmpqxlqi07y/migrations/base/saas~16.5.1.3/end-01-attrs-views.py", line 122, in fix_archs if not fix_attrs(cr, v.model, arch, comb_arch): File "/tmp/tmpqxlqi07y/migrations/base/17.0.1.3/attr_domains2expr.py", line 362, in fix_attrs success &= fix_elem(cr, model, elem, comb_arch) File "/tmp/tmpqxlqi07y/migrations/base/17.0.1.3/attr_domains2expr.py", line 326, in fix_elem elem.set(key, value) File "src/lxml/etree.pyx", line 831, in lxml.etree._Element.set File "src/lxml/apihelpers.pxi", line 585, in lxml.etree._setAttributeValue File "src/lxml/apihelpers.pxi", line 1763, in lxml.etree._attributeValidOrRaise ValueError: Invalid attribute name '!required' ``` closes #122 Signed-off-by: Christophe Simonis (chs) <[email protected]>
1 parent 0d7d609 commit f234ed4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/base/17.0.1.3/attr_domains2expr.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,13 @@ def fix_elem(cr, model, elem, comb_arch):
320320
)
321321
for key in extra:
322322
value = ast.unparse(attrs[key])
323-
_logger.info("Inlined %s=%r", key, value)
324-
elem.set(key, value)
323+
try:
324+
etree.QName(key)
325+
except ValueError as e:
326+
_logger.error("Skipping invalid attribute name %r in `attrs` with value: %s: %r", key, value, e) # noqa: TRY400
327+
else:
328+
elem.set(key, value)
329+
_logger.info("Inlined %s=%r", key, value)
325330

326331
return success
327332

0 commit comments

Comments
 (0)