spacetelescope/stdatamodels

schema editor `merge_schemas` modifies input schemas

Closed this issue · 0 comments

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:

keyword_db = Keyword_db(self.input)
keyword_dict = keyword_db.create_dict()
keyword_schema = keyword_db.schema

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.