Skip to content

Preserve context when querying and inserting content items - #488

Merged
CPBridge merged 5 commits into
ImagingDataCommons:masterfrom
jdotc1:bugfix/jdotc1-content-sequence-context-20261022
Nov 1, 2026
Merged

CPBridge merged 5 commits into
ImagingDataCommons:masterfrom
jdotc1:bugfix/jdotc1-content-sequence-context-20261022

Conversation

@jdotc1

@jdotc1 jdotc1 commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

ContentSequence queries discard root/non-SR context or call an incompatible template subclass constructor; insert rejects a valid relationship-free non-SR item.

Preserve both context flags in query results, return a base ContentSequence with an accurate annotation, and make insertion respect SR/non-SR relationship requirements before mutating storage or its lookup table.

Related to #479/#480, but #480 is already merged and this patch targets distinct remaining paths. Do not reopen or auto-close those records.

Testing

3 query checks and 6 insertion checks pass using the actual method/guard excerpts with explicit storage and content-item stand-ins. Baseline: 3 query failures; insertion harness separately fails 2 cases and passes 4 on the original context guard.

Not executed: Real highdicom/pydicom constructors, template decoding, the existing 29 ContentSequence tests, SR suite, Flake8 and mypy were not executed.

Compatibility

get_nodes now deliberately returns the documented base sequence rather than an arbitrary template subclass. The patch does not attempt to repair every pre-existing append/setitem validation inconsistency.

@CPBridge CPBridge added the bug Something isn't working label Oct 22, 2026
@jdotc1

jdotc1 commented Oct 24, 2026

Copy link
Copy Markdown
Contributor Author

Resolved the merge conflict against upstream master (12b1287) while retaining both this PR’s ContentSequence regression cases and upstream’s temporal-coordinates tests. The full suite passed locally (2,105 passed, 173 skipped due to unavailable optional dependencies). GitHub now reports this PR mergeable.

@CPBridge CPBridge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jdotc1 , indeed this part of the API has not got a lot of love recently and is overdue a tidy up. One small request

Comment thread tests/test_sr.py Outdated
assert len(sequence.find(item.name)) == 1

sr_sequence = ContentSequence([])
with pytest.raises(AttributeError):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One minor request. Could you please add a match guard here and everywhere else you use pytest.raises so that we are sure we are hitting the intended exception and getting the right message?

@CPBridge CPBridge left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@CPBridge
CPBridge merged commit 1a05012 into ImagingDataCommons:master Nov 1, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants