Skip to content

Fix iterparse XES importer crashing on a nested <list> inside a list-of-values - #568

Open
mittalpk wants to merge 1 commit into
process-intelligence-solutions:releasefrom
mittalpk:fix/xes-nested-list-log-attributes
Open

Fix iterparse XES importer crashing on a nested <list> inside a list-of-values#568
mittalpk wants to merge 1 commit into
process-intelligence-solutions:releasefrom
mittalpk:fix/xes-nested-list-log-attributes

Conversation

@mittalpk

Copy link
Copy Markdown
Contributor

Fixes #566.

What's wrong

pm4py.read_xes()'s actual default variant is iterparse whenever lxml is installed (constants.DEFAULT_XES_PARSER), not chunk_regex as the docstring states. iterparse.py's __parse_attribute() crashes with TypeError: list indices must be integers or slices, not str on any XES file containing a <list> element nested inside another <list>'s <values> block — e.g. a log-level kpi list 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 through store[key] = {...} — which crashes because store is a list, not a dict. The sibling "leaf value" branch a few lines above already handled this correctly (store.append((key, value)) when store is 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) or store[key] = entry (dict store) — reusing the exact pattern already used for leaf values, rather than assuming store is always a dict.

Testing

  • Reproduced the exact reported error with a minimal XES file matching the issue's structure (a log-level list containing a nested list with its own nested attributes, and a sibling list containing two nested sub-lists), against the real default (variant='iterparse', i.e. lxml installed). Confirmed chunk_regex and line_by_line do not hit this bug, only iterparse. Fails on unpatched code, passes after the fix (checked via git stash isolation of just the fix file).
  • Added test_iterparse_nested_list_inside_a_list_of_values to tests/xes_deep_coverage_test.py, asserting the parsed nested structure matches the source XES exactly.
  • Ran xes_deep_coverage_test.py, xes_impexp_test.py (including its "problematic/malformed logs" coverage), facade_utils_coverage_test.py, and main_fac_test.py — 33 tests total, all pass, no regressions.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XES files with nested list attributes is not imported

1 participant