diff --git a/liminal/entity_schemas/compare.py b/liminal/entity_schemas/compare.py index 1d43d0c..b20c1d3 100644 --- a/liminal/entity_schemas/compare.py +++ b/liminal/entity_schemas/compare.py @@ -232,6 +232,28 @@ def compare_entity_schemas( ) ) if benchling_schema_props != model.__schema_properties__: + needs_constraint_clear = ( + benchling_schema_props.constraint_fields + != model.__schema_properties__.constraint_fields + and len(benchling_schema_props.constraint_fields) > 0 + ) + if needs_constraint_clear: + ops.append( + CompareOperation( + op=UpdateEntitySchema( + model.__schema_properties__.warehouse_name, + BaseSchemaProperties(constraint_fields=set()), + ), + reverse_op=UpdateEntitySchema( + model.__schema_properties__.warehouse_name, + BaseSchemaProperties( + **model.__schema_properties__.merge( + benchling_schema_props + ) + ), + ), + ) + ) ops.append( CompareOperation( op=UpdateEntitySchema( @@ -244,7 +266,9 @@ def compare_entity_schemas( ), reverse_op=UpdateEntitySchema( model.__schema_properties__.warehouse_name, - BaseSchemaProperties( + BaseSchemaProperties(constraint_fields=set()) + if needs_constraint_clear + else BaseSchemaProperties( **model.__schema_properties__.merge( benchling_schema_props ) diff --git a/liminal/tests/test_entity_schema_compare.py b/liminal/tests/test_entity_schema_compare.py index a13ad3b..0d0ddd5 100644 --- a/liminal/tests/test_entity_schema_compare.py +++ b/liminal/tests/test_entity_schema_compare.py @@ -361,13 +361,21 @@ def test_compare_benchling_schema_fields( # type: ignore[no-untyped-def] benchling_mismatch_constraint_fields ) invalid_models = compare_entity_schemas(mock_benchling_sdk) - assert len(invalid_models["mock_entity"]) == 1 + assert len(invalid_models["mock_entity"]) == 2 assert isinstance(invalid_models["mock_entity"][0].op, UpdateEntitySchema) - assert invalid_models["mock_entity"][ + clear_props_dict = invalid_models["mock_entity"][ 0 - ].op.update_props.constraint_fields == { - "string_field_req", - "enum_field", + ].op.update_props.model_dump(exclude_unset=True) + assert clear_props_dict == {"constraint_fields": set()} + assert isinstance(invalid_models["mock_entity"][1].op, UpdateEntitySchema) + update_props_dict = invalid_models["mock_entity"][ + 1 + ].op.update_props.model_dump(exclude_unset=True) + assert update_props_dict == { + "constraint_fields": { + "string_field_req", + "enum_field", + }, } # Test when the Benchling schema has different display naming fields