diff --git a/changes/356.bugfix.rst b/changes/356.bugfix.rst new file mode 100644 index 00000000..faf9cfc0 --- /dev/null +++ b/changes/356.bugfix.rst @@ -0,0 +1 @@ +Avoid unnecessary validation on Model.__init__. diff --git a/src/stdatamodels/jwst/datamodels/tests/test_multislit.py b/src/stdatamodels/jwst/datamodels/tests/test_multislit.py index 27b2c65d..8fce6821 100644 --- a/src/stdatamodels/jwst/datamodels/tests/test_multislit.py +++ b/src/stdatamodels/jwst/datamodels/tests/test_multislit.py @@ -5,7 +5,7 @@ from numpy.testing import assert_array_equal import pytest -from stdatamodels.jwst.datamodels import MultiSlitModel, ImageModel +from stdatamodels.jwst.datamodels import MultiSlitModel, ImageModel, SlitModel def test_multislit_model(): @@ -155,3 +155,12 @@ def test_copy_multislit(): assert model1.slits[0].data[330, 330] == 1 assert output.slits[0].data[330, 330] == -1 + + +def test_slit_from_multislit(): + model = MultiSlitModel() + slit = SlitModel() + # access int_times so it's created + slit.int_times = slit.int_times + model.slits.append(slit) + slit = SlitModel(model.slits[0].instance) diff --git a/src/stdatamodels/model_base.py b/src/stdatamodels/model_base.py index a231a7d9..9042607d 100644 --- a/src/stdatamodels/model_base.py +++ b/src/stdatamodels/model_base.py @@ -566,6 +566,11 @@ def open_asdf(init=None, ignore_unrecognized_tag=ignore_unrecognized_tag, **kwargs) + elif isinstance(init, dict): + asdffile = AsdfFile(None, + ignore_unrecognized_tag=ignore_unrecognized_tag + ) + asdffile._tree = init else: asdffile = AsdfFile(init, ignore_unrecognized_tag=ignore_unrecognized_tag