Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion liminal/entity_schemas/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
)
Expand Down
18 changes: 13 additions & 5 deletions liminal/tests/test_entity_schema_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading