Skip to content

adapter.aasx: Fix KeyError on missing supplementary file - #684

Open
Adamvalade wants to merge 1 commit into
eclipse-basyx:developfrom
Adamvalade:fix/missing-supplementary-file
Open

Adamvalade wants to merge 1 commit into
eclipse-basyx:developfrom
Adamvalade:fix/missing-supplementary-file

Conversation

@Adamvalade

Copy link
Copy Markdown

Bug

AASXReader.read_into() raises KeyError: 'Could not find part ... in package' when a File element or the default thumbnail references a part that is not contained in the AASX package, even with failsafe=True. The object is already added to the object store at that point, so reading stops half-way and all remaining objects are lost. Our own AASXWriter produces such packages in failsafe mode when a supplementary file is missing from the file store, so the reader should accept them.

Fix

In AASXReader._add_supplementary_file(), the KeyError from self.reader.open_part() is now handled according to the failsafe flag, mirroring the existing error-handling conventions in this module and in AASXWriter:

  • With failsafe=True, the missing part is logged as a warning and None is returned. The callers in _collect_supplementary_files() already handle None, so the File element / default thumbnail keeps its original reference and reading continues with the remaining elements and objects.
  • With failsafe=False, a KeyError naming the missing supplementary file is raised (chained from the original error), preserving the previous exception type.

The try block is intentionally scoped to open_part() only, so unrelated exceptions from the supplementary file container (e.g. a KeyError raised inside a custom add_file() implementation) are not swallowed.

Regression tests

Added to AASXReaderTest in sdk/test/adapter/aasx/test_aasx.py, building packages without the referenced part via the failsafe writer:

  • test_reading_with_missing_file: missing supplementary file of a File element in both failsafe modes (warning + fully preserved object and unchanged File.value with failsafe=True; KeyError with failsafe=False).
  • test_reading_with_missing_default_thumbnail: same for a missing default thumbnail of an AAS in both failsafe modes.
  • test_reading_missing_and_valid_supplementary_files: a missing file followed by a valid one; the valid file is still loaded (content type and content hash verified).

Verification

  • Focused AASX tests: python -m unittest test.adapter.aasx.test_aasx — 22 tests OK.
  • All adapter tests: python -m unittest discover -s test/adapter -t . — 85 tests OK (2 pre-existing schema-dependent skips).
  • ruff check and mypy basyx test pass.

The full test suite was not run locally, since it requires a CouchDB service and downloaded AAS schemas that are only provided in CI.

Fixes #665

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.

1 participant