Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove assignment validation #417

Merged
merged 6 commits into from
Nov 22, 2024

Conversation

braingram
Copy link
Collaborator

@braingram braingram commented Nov 7, 2024

This PR removes validation on attribute assignment for roman datamodels. This change was discussed during a recent roman calibration tag up and the consensus was that removing this feature will make handling TVAC data easier (and potentially older versions of files once RAD schemas/roman_datamodels are versioned).

With this PR we could consider removing "nuke_validation". The reasoning is that disabling validate_on_read now allows reading old/invalid files. Let's say I have a file "foo.asdf" with FOO_IMAGE as exposure_type-1.0.0. On roman_datamodels main if I try to open this file I get an error:

>> import asdf
>> from roman_datamodels import datamodels as dm
>> m = dm.open("foo.asdf")
ValidationError: 'FOO_IMAGE' is not one of ['WFI_IMAGE', 'WFI_GRISM', 'WFI_PRISM', 'WFI_DARK', 'WFI_FLAT', 'WFI_WFSC']

On main disabling validate_on_read doesn't prevent this error since roman_datamodels will still validate each assignment. However, with this PR disabling validate_on_read allows the file to be opened:

>> cfg = asdf.config.get_config()
>> cfg.validate_on_read = False
>> m = dm.open("foo.asdf")
<roman_datamodels.datamodels._datamodels.ImageModel at 0x161f96890>

Since this PR disables assignment validation there's no need to "nuke validation" for assignments. However there would still be a use for this feature if we want to be able to save invalid files.

If a user wants to write an invalid file I think it makes more sense for that file to not use RAD tags/schemas.

Regression tests https://github.com/spacetelescope/RegressionTests/actions/runs/11731951627
show one doctest failure due to the romancal docs testing assignment validation. This failure is addressed in spacetelescope/romancal#1504

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

@braingram braingram changed the title No assignment validation Remove assignment validation Nov 7, 2024
Copy link

codecov bot commented Nov 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.41%. Comparing base (087a60d) to head (a61272d).
Report is 76 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #417      +/-   ##
==========================================
- Coverage   97.56%   97.41%   -0.15%     
==========================================
  Files          30       36       +6     
  Lines        2788     3294     +506     
==========================================
+ Hits         2720     3209     +489     
- Misses         68       85      +17     

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


🚨 Try these New Features:

@braingram

This comment was marked as outdated.

@braingram braingram marked this pull request as ready for review November 8, 2024 16:44
@braingram braingram requested a review from a team as a code owner November 8, 2024 16:44
@braingram braingram requested a review from PaulHuwe November 8, 2024 16:44
@braingram braingram force-pushed the no_assignment_validation branch from 19aa07a to bd4e025 Compare November 15, 2024 17:24
@braingram braingram force-pushed the no_assignment_validation branch from bd4e025 to 4cb17a3 Compare November 18, 2024 15:46
@schlafly
Copy link
Collaborator

I'm happy when you and William are. There's some magic in the current code where knowledge about how using dot notation triggers validation and dictionary notation does not, and a nice feature of this is that that magic will go away, I think?

Copy link
Collaborator

@mairanteodoro mairanteodoro left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks, @braingram!
Just one question: will the validation still happen on saving the file?

@braingram
Copy link
Collaborator Author

Looks good! Thanks, @braingram! Just one question: will the validation still happen on saving the file?

Thanks! Yeah, asdf will always validate before saving (although roman_datamodels prevents this when "nuke validation is enabled allowing saving invalid files).

@braingram braingram force-pushed the no_assignment_validation branch from 4cb17a3 to a61272d Compare November 20, 2024 14:15
Copy link
Collaborator

@PaulHuwe PaulHuwe left a comment

Choose a reason for hiding this comment

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

LGTM. Can you wait to merge until @WilliamJamieson approves?

Copy link
Collaborator

@WilliamJamieson WilliamJamieson left a comment

Choose a reason for hiding this comment

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

These changes are fine with me. More cleanup can probably be done but that is outside the scope of this PR.

@braingram braingram merged commit ab68c35 into spacetelescope:main Nov 22, 2024
17 of 18 checks passed
@braingram braingram deleted the no_assignment_validation branch November 22, 2024 18:43
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.

5 participants