Fix iterparse XES importer crashing on a nested <list> inside a list-of-values - #568
Open
mittalpk wants to merge 1 commit into
Open
Conversation
…of-values
__parse_attribute()'s children-container branch always did
store[key] = {...}, assuming store is a dict. When an element's
container was built as a list() (because its parent's first child
was <values>, signaling a list-of-values rather than a dict of named
attributes), a nested <list> element inside it crashed with
TypeError: list indices must be integers or slices, not str.
The sibling leaf-value branch already handled this correctly via
store.append((key, value)) when store is a list; mirror that for
nested lists by building the entry first and branching on append vs
assignment.
Fixes process-intelligence-solutions#566
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.
Fixes #566.
What's wrong
pm4py.read_xes()'s actual default variant isiterparsewheneverlxmlis installed (constants.DEFAULT_XES_PARSER), notchunk_regexas the docstring states.iterparse.py's__parse_attribute()crashes withTypeError: list indices must be integers or slices, not stron any XES file containing a<list>element nested inside another<list>'s<values>block — e.g. a log-levelkpilist containing several named sub-lists (OTC-ON,OTC-CN), exactly as in the reported file.The root cause: when an element's own children container is a
list()(because its parent's first child tag was<values>, signaling "this is a list of values, not a dict of named attributes"), any nested<list>element inside it still went throughstore[key] = {...}— which crashes becausestoreis a list, not a dict. The sibling "leaf value" branch a few lines above already handled this correctly (store.append((key, value))whenstoreis a list); the "has children" branch just never mirrored that handling for nested lists.Fix
__parse_attribute()now builds the child-entry dict first, then branches only on whether to.append((key, entry))(list store) orstore[key] = entry(dict store) — reusing the exact pattern already used for leaf values, rather than assumingstoreis always a dict.Testing
variant='iterparse', i.e.lxmlinstalled). Confirmedchunk_regexandline_by_linedo not hit this bug, onlyiterparse. Fails on unpatched code, passes after the fix (checked viagit stashisolation of just the fix file).test_iterparse_nested_list_inside_a_list_of_valuestotests/xes_deep_coverage_test.py, asserting the parsed nested structure matches the source XES exactly.xes_deep_coverage_test.py,xes_impexp_test.py(including its "problematic/malformed logs" coverage),facade_utils_coverage_test.py, andmain_fac_test.py— 33 tests total, all pass, no regressions.