spacetelescope / stdatamodels

https://stdatamodels.readthedocs.io
Other
5 stars 24 forks source link

schema editor `merge_schemas` modifies input schemas #226

Closed braingram closed 9 months ago

braingram commented 11 months ago

Calling merge_schemas modifies the inputs. A minimal example is as follows:

import stdatamodels.jwst.datamodels.schema_editor
s0 = {'title': 'a'}
s1 = {'title': 'b'}
merged = stdatamodels.jwst.datamodels.schema_editor.Keyword_db.merge_schemas(None, [s0, s1])
assert merged['title'] == 'b'
assert s1['title'] == 'b'
assert s0['title'] == 'b'

This creates an issue during combining the keywords into a schema: https://github.com/spacetelescope/stdatamodels/blob/15e5ae69d75658138960ecafac59115aad376eb6/src/stdatamodels/jwst/datamodels/schema_editor.py#L985-L987 The call to create_dict (which calls merge_schemas) modifies the schema created from the keyword files. This can be seen by stepping through the above code in pdb. After line 985 the following is False

'subpixel_number' in keyword_db.schema['properties']['meta']['properties']['dither']['properties']['allOf'][0]

After line 986 the above is True as the first item was modified by a call to merge_schemas.