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 the target keyword from rdm_open #235

Conversation

WilliamJamieson
Copy link
Collaborator

@WilliamJamieson WilliamJamieson commented Jul 6, 2023

This PR addresses issue #51 and the partial solution to it in PR #52. The solution in #52 was to add the target keyword to rdm_open, however it did not fix the actual issue from #51. Then in PR #59, the tests for the solution in #52 were completely removed, and after that point the target argument completely ceased being used in roman_datamodels and romancal.

The issue at hand in #51 is that if we pass a data model instance to the datamodel constructor (<data_model_class>(*args, **kwargs)), then we don't want it to raise an error. The discussion and solution in #52 additionally indicates the we should pass the exact object out with no alterations rather than constructing a new object.

This pull request adds a test reproducing the error described in #51 together with the additional constraints from #52. It then solves the issue via injecting a new __new__ method for the DataModel objects which detects and then handles this case special case. It then reverts the partial solution from #52.

Checklist

@WilliamJamieson WilliamJamieson requested a review from a team as a code owner July 6, 2023 23:00
of the model. In this case the constructor should just directly return
the model.
"""
if init.__class__.__name__ == cls.__name__:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Bad things happen (infinite recursion) if one tries to isinstance checks here.

@WilliamJamieson WilliamJamieson force-pushed the feature/pass_like_to_datamodel_constructor branch from b722011 to 402c887 Compare July 7, 2023 19:33
@codecov
Copy link

codecov bot commented Jul 7, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.53 🎉

Comparison is base (c0a084d) 94.47% compared to head (23d5233) 95.00%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #235      +/-   ##
==========================================
+ Coverage   94.47%   95.00%   +0.53%     
==========================================
  Files          23       23              
  Lines        1628     1621       -7     
==========================================
+ Hits         1538     1540       +2     
+ Misses         90       81       -9     
Impacted Files Coverage Δ
src/roman_datamodels/datamodels/_core.py 90.00% <100.00%> (+0.32%) ⬆️
src/roman_datamodels/datamodels/_utils.py 91.17% <100.00%> (+16.70%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@WilliamJamieson WilliamJamieson force-pushed the feature/pass_like_to_datamodel_constructor branch from 402c887 to 23d5233 Compare July 7, 2023 19:35
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

@WilliamJamieson WilliamJamieson force-pushed the feature/pass_like_to_datamodel_constructor branch from 23d5233 to 100e32e Compare July 7, 2023 23:04
Issue spacetelescope#51 and PR spacetelescope#52 indicate that we should be able to pass a
model instance to a matching model's constructor, and then
return exactly the same instance unmodified.
@WilliamJamieson WilliamJamieson force-pushed the feature/pass_like_to_datamodel_constructor branch from 100e32e to e0bcccd Compare July 7, 2023 23:08
@WilliamJamieson WilliamJamieson merged commit 46e722b into spacetelescope:main Jul 7, 2023
@WilliamJamieson WilliamJamieson deleted the feature/pass_like_to_datamodel_constructor branch July 7, 2023 23:12
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