Fix CopyDirective exclude/exclude_all on slot-list classes#244
Open
amc-corey-cox wants to merge 4 commits into
Open
Fix CopyDirective exclude/exclude_all on slot-list classes#244amc-corey-cox wants to merge 4 commits into
amc-corey-cox wants to merge 4 commits into
Conversation
The _copy_list path (used when a source class declares slots as a list rather than inline attributes) had two bugs: - `exclude` checked the directive's truthiness instead of membership, so it removed every source slot. - `exclude_all` mutated the list while iterating, leaving half intact. Mirror _copy_dict's behavior and clear() the list. Add parametrized tests covering exclude, exclude_all, include, and combinations on the slot-list path. Closes #67
This was referenced May 14, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes SchemaMapper._copy_list so CopyDirective.exclude and exclude_all behave correctly when copying slot-list classes (i.e., classes that declare slots: [...] rather than inline attributes). Adds regression tests to cover these directive behaviors on the slot-list path (closing #67).
Changes:
- Correct
excludelogic in_copy_listto remove only specified elements rather than removing everything. - Fix
exclude_alllogic in_copy_listby clearing the target list safely. - Add parametrized tests covering
copy_all,exclude,exclude_all, andincludefor slot-list classes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/linkml_map/inference/schema_mapper.py |
Fixes CopyDirective handling for list-based slot copying (exclude / exclude_all). |
tests/test_schema_mapper/test_schema_mapper.py |
Adds regression tests for CopyDirective behavior on slot-list classes. |
Comments suppressed due to low confidence (1)
src/linkml_map/inference/schema_mapper.py:92
- In
_copy_list, theincludestep appends elements unconditionally. If a directive usescopy_all=True(or multiple directives run) and also setsinclude, this will duplicate slot names intgt_elements, which can make the derived schema invalid or at least surprising. Consider making list-copy idempotent by only appending when the element is not already present (or by maintaining an order-preserving set) duringcopy_all/includeoperations.
tgt_elements.clear()
if copy_directive.include:
for element in copy_directive.include:
if element in src_elements:
tgt_elements.append(element)
The slot-list path appends unconditionally, so `copy_all=True` combined with `include=[...]` (or any combination where the same name is reached twice) produces duplicate slot names in the target class. Guard both branches with a membership check. Add a parametrized case covering copy_all + include.
…p into fix-copy-directive-list
Comment on lines
80
to
+83
| if copy_directive.copy_all: | ||
| for element in src_elements: | ||
| tgt_elements.append(element) | ||
| if element not in tgt_elements: | ||
| tgt_elements.append(element) |
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.
The
_copy_listpath inSchemaMapper(used when a source class declares its slots as a list rather than inline attributes) had two bugs that madeexcludeandexclude_allnon-functional:excludechecked the directive's truthiness instead of membership, so it removed every source slot.exclude_allmutated the list while iterating, leaving roughly half the elements intact.Mirrors
_copy_dict's behavior (iterate the exclude list, check membership in the target) and useslist.clear()forexclude_all. Adds parametrized tests coveringexclude,exclude_all,include, and combinations on the slot-list path — none of this was previously covered.Closes #67.
Two related items deliberately left out of scope, to be filed as follow-ups:
CopyDirective.addslot is declared in the YAML schema but has no description and no implementation. Needs design.excludeandincludeslots in theCopyDirectiveclass #67's body) is a different feature, likely belonging onSlotDerivation.target_definition.