Repository navigation
adapter.aasx: Fix KeyError on missing supplementary file - #684
Open
Adamvalade wants to merge 1 commit into
Open
Adamvalade wants to merge 1 commit into
Adamvalade wants to merge 1 commit into
Conversation
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.
Bug
AASXReader.read_into()raisesKeyError: 'Could not find part ... in package'when aFileelement or the default thumbnail references a part that is not contained in the AASX package, even withfailsafe=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 ownAASXWriterproduces 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(), theKeyErrorfromself.reader.open_part()is now handled according to thefailsafeflag, mirroring the existing error-handling conventions in this module and inAASXWriter:failsafe=True, the missing part is logged as a warning andNoneis returned. The callers in_collect_supplementary_files()already handleNone, so theFileelement / default thumbnail keeps its original reference and reading continues with the remaining elements and objects.failsafe=False, aKeyErrornaming the missing supplementary file is raised (chained from the original error), preserving the previous exception type.The
tryblock is intentionally scoped toopen_part()only, so unrelated exceptions from the supplementary file container (e.g. aKeyErrorraised inside a customadd_file()implementation) are not swallowed.Regression tests
Added to
AASXReaderTestinsdk/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 aFileelement in both failsafe modes (warning + fully preserved object and unchangedFile.valuewithfailsafe=True;KeyErrorwithfailsafe=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
python -m unittest test.adapter.aasx.test_aasx— 22 tests OK.python -m unittest discover -s test/adapter -t .— 85 tests OK (2 pre-existing schema-dependent skips).ruff checkandmypy basyx testpass.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