fix: raise TrestleError when get_singular_alias path ends with numeric index#2144
Open
Acuspeedster wants to merge 2 commits intooscal-compass:developfrom
Open
Conversation
…c index (oscal-compass#2140) Signed-off-by: Acuspeedster <arnavrajsingh@gmail.com>
…c index (oscal-compass#2140) Signed-off-by: Acuspeedster <arnavrajsingh@gmail.com>
|
Hi @Acuspeedster, thanks for the PR and the effort! Since I opened this issue and am already working on it, could you please close this PR for now to avoid duplicate work? |
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.
PR Title
fix: raise TrestleError when get_singular_alias path ends with numeric index (#2140)
Closes #2140
Types of changes
develop->main)Quality assurance (all should be covered).
Summary
ModelUtils.get_singular_alias()previously returned the numeric index string (e.g.'0') when called with a path that terminates on an array index such ascomponent-definition.components.0. This is meaningless as an alias and was explicitly flagged in the test suite with a# FIXME ideally this should report errorcomment.Root cause
In
get_singular_alias(), after the traversal loop, the branch that handles non-collection terminal model types (if not utils.is_collection_field_type(model_type)) returnedlast_aliaswithout checking whether it was a numeric index. When an index like0was the last path segment, the loop unwrapped the collection's inner type (leaving a non-collection model type) and the function fell straight through toreturn last_alias, returning'0'.Fix
Added a guard after extracting
last_aliasto check whether it is a pure digit string. If so, aTrestleErroris raised with a clear message before any further processing.Numeric indices appearing in the middle of a path (e.g.
component-definition.components.0.control-implementations) continue to work correctly and are unaffected.Changes
trestle/common/model_utils.pyelif last_alias.isdigit()guard to raiseTrestleErrortests/trestle/utils/fs_test.pyassert '0' == ...+# FIXMEwithpytest.raises(TrestleError)Closes #2140
Key links:
Before you merge