Conversation
When the XML file contains no tag (e.g. an empty file), _get_first_tag
returned the Python str ''. The success branch returns bytes from
b' '.join(buffer), and check_xml_header consumes the result with
first_tag.startswith(b'<?xml '), which raises:
TypeError: startswith first arg must be str or a tuple of str, not bytes
Return b'' in the no-tag path so both branches are type-consistent and
downstream bytes operations keep working.
Collaborator
|
Gracias Papito! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When an XML file in the inspected module contains no tag (e.g. an empty
.xmlfile),ChecksOdooModuleXML._get_first_tagreturns the Pythonstr''. The success branch of the same method returns bytes fromb' '.join(buffer), and downstream code incheck_xml_headerconsumes the result as bytes:When
first_tagisstr,startswith(bytes)raises:This crashes the entire hook for the repository as soon as one empty/tag-less XML file exists anywhere in the inspected modules — even if
xml-header-missingis disabled, because the mismatch happens before the enablement check.Reproduction
The existing
test_repo/broken_module/xml_empty.xmlfixture is a 0-byte file and reproduces the issue on real hook runs.Fix
Return
b""instead of""in the no-tag path so both branches of_get_first_tagare type-consistent (always bytes), and downstreamstartswith(b"<?xml ")/decode("UTF-8")calls keep working.One-line change in
src/oca_pre_commit_hooks/checks_odoo_module_xml.py.Notes
Found while running v0.2.20 against an Odoo 19 addon that contains an empty XML file. The local test suite does not run on Python 3.14 (distutils removed) so verification was done via targeted reproduction; CI will validate against the supported matrix.