Skip to content

Commit c7c95cf

Browse files
aj-fuentescawo-odoo
andcommitted
[FIX] util/records: do not fail on extra encoded CR char
When some views have a `\r` encoded char `&#13;` the lxml parser fails with the error: ``` Traceback (most recent call last): ... File "/tmp/tmpbtt99q0o/migrations/util/fields.py", line 444, in rename_field update_field_usage(cr, model, old, new, domain_adapter=domain_adapter, skip_inherit="*") File "/tmp/tmpbtt99q0o/migrations/util/fields.py", line 785, in update_field_usage return _update_field_usage_multi(cr, [model], old, new, domain_adapter=domain_adapter, skip_inherit=skip_inherit) File "/tmp/tmpbtt99q0o/migrations/util/fields.py", line 971, in _update_field_usage_multi adapt_domains(cr, model, old, new, adapter=domain_adapter, skip_inherit="*", force_adapt=True) File "/tmp/tmpbtt99q0o/migrations/util/domains.py", line 313, in adapt_domains with suppress(_Skip), edit_view(cr, view_id=view_id, active=None) as view: File "/usr/lib/python3.8/contextlib.py", line 113, in __enter__ return next(self.gen) File "/tmp/tmpbtt99q0o/migrations/util/records.py", line 223, in edit_view arch_etree = lxml.etree.fromstring(arch) File "src/lxml/etree.pyx", line 3257, in lxml.etree.fromstring File "src/lxml/parser.pxi", line 1916, in lxml.etree._parseMemoryDocument File "src/lxml/parser.pxi", line 1803, in lxml.etree._parseDoc File "src/lxml/parser.pxi", line 1144, in lxml.etree._BaseParser._parseDoc File "src/lxml/parser.pxi", line 618, in lxml.etree._ParserContext._handleParseResultDoc File "src/lxml/parser.pxi", line 728, in lxml.etree._handleParseResult File "src/lxml/parser.pxi", line 657, in lxml.etree._raiseParseError File "<string>", line 270 lxml.etree.XMLSyntaxError: Extra content at the end of the document, line 270, column 5 ``` ``` 1154528_afu=> select id,SUBSTR(arch_db,1,100) from ir_ui_view where arch_db like '%&#13;%' +------+-------------------------------------------------------+ | id | substr | |------+-------------------------------------------------------| | 3856 | <t t-name="website.domestic-violence-awareness">&#13; | | | <t t-call="website.layout">&#13; | | | <div id | +------+-------------------------------------------------------+ ``` Since we make `unicode=str` in Python3 we are always encoding strings into bytes. Note that `u"".encode("utf-8")` in Python2 is not the same as `"".encode("utf-8")` in Python3. The latter returns a bytes string, while the former returns a string. In Python2 the replace works also with `b` prefix. upg-1154528 upg-1155580 Part-of: odoo/upgrade#5307 Co-authored-by: "Carsten Wolff (cawo)" <[email protected]>
1 parent 7d5a89d commit c7c95cf

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/util/records.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def get_trans_terms(value):
220220
else:
221221
if isinstance(arch, unicode):
222222
arch = arch.encode("utf-8")
223-
arch_etree = lxml.etree.fromstring(arch)
223+
arch_etree = lxml.etree.fromstring(arch.replace(b"&#13;\n", b"\n"))
224224
yield arch_etree
225225
arch_column_value = lxml.etree.tostring(arch_etree, encoding="unicode")
226226

0 commit comments

Comments
 (0)