Skip to content

Handle missing minItems.#692

Draft
schlafly wants to merge 2 commits into
spacetelescope:mainfrom
schlafly:handle-missing-minitems
Draft

Handle missing minItems.#692
schlafly wants to merge 2 commits into
spacetelescope:mainfrom
schlafly:handle-missing-minitems

Conversation

@schlafly

@schlafly schlafly commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

This PR intends to improve the handling of read_pattern and other attributes lacking minItems (c.f. spacetelescope/romancal#2390). Really a Claude PR deserving more scrutiny.

Tasks

  • Update or add relevant roman_datamodels tests.
  • Update relevant docstrings and / or docs/ page.
  • Does this PR change any API used downstream? (If not, label with no-changelog-entry-needed.)
News fragment change types:
  • changes/<PR#>.feature.rst: new feature
  • changes/<PR#>.bugfix.rst: fixes an issue
  • changes/<PR#>.doc.rst: documentation change
  • changes/<PR#>.removal.rst: deprecation or removal of public API
  • changes/<PR#>.misc.rst: infrastructure or miscellaneous change

@codecov

codecov Bot commented Jul 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.17%. Comparing base (8f616fa) to head (84c5bd4).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #692      +/-   ##
==========================================
- Coverage   95.21%   95.17%   -0.04%     
==========================================
  Files          27       27              
  Lines        2861     2861              
==========================================
- Hits         2724     2723       -1     
- Misses        137      138       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

# No minimum length is imposed by the schema, so keep however many
# defaults were provided (as the scalar builders do) instead of
# discarding them. Without a default this yields an empty array.
min_items = len(defaults)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The general strategy here is that create_minimal only uses defaults if the item is required.
read_pattern is required but the items/structure is undefined in the schema:
https://github.com/spacetelescope/rad/blob/f82c94f91e8afabf3348a2be870790c8f129f6b6/latest/meta/exposure.yaml#L261
So the minimal amount that can be taken from the defaults and is valid is an empty read pattern.
I'm ok with the approach in this PR (if the schema has no minItems but a default was provided, use the defaults) given the limited use of lists/arrays in our schemas. An alternative would be to propagate read_pattern in romancal (since I don't see a way for us to define minItems or something similar in the schema).
Given the defaults is copied below (341) and then len checked (344) I think we could replace this line with:

Suggested change
min_items = len(defaults)
return copy.deepcopy(defaults)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The test in spacetelescope/romancal#2390 only checks read_pattern but there are a handful of other related cases the code should be able to handle (image_shape; rotation_matrix; dither_executed_pattern). Do you see a mechanism to propagate these generically in romancal? It seemed more fragile to list out those cases.

I'm happy with replacing the min_items definition with the direct copy; an earlier version took that approach but I decided it was nicer to follow the path here. I don't have a strong preference.

Re "The general strategy here is that create_minimal only uses defaults if the item is required."---this change is intended to fix
https://github.com/spacetelescope/romancal/blob/main/romancal/source_catalog/source_catalog_step.py#L317-L319
where conceptually we want to bring over the old metadata into the new object for relevant fields. In that context, all things being equal, I'd rather also propagate optional fields, and when copying things over, we want to copy all of them. Do you think that instead we should be using something other than create_minimal there?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If optional fields are also wanted than maybe this should be using create_from_model instead of create_minimal?

I tried this PR with a few other attributes and one thing to note is that now cal_logs are copied from the defaults for create_minimal. I don't think that's an issue (since those should be overwritten when a step finishes).

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.

2 participants