diff --git a/backend/infrahub/core/node/constraints/grouped_uniqueness.py b/backend/infrahub/core/node/constraints/grouped_uniqueness.py index 76f6d64c98..8558f3272b 100644 --- a/backend/infrahub/core/node/constraints/grouped_uniqueness.py +++ b/backend/infrahub/core/node/constraints/grouped_uniqueness.py @@ -97,7 +97,10 @@ async def _get_node_attribute_path_values( attribute_field = getattr(updated_node, attribute_name) attribute_value = getattr(attribute_field, schema_attribute_path.attribute_property_name or "value") node_value_combination.append( - SchemaAttributePathValue.from_schema_attribute_path(schema_attribute_path, value=attribute_value) + SchemaAttributePathValue.from_schema_attribute_path( + schema_attribute_path, + value=attribute_value.value if attribute_field.is_enum else attribute_value, + ) ) return node_value_combination diff --git a/backend/tests/unit/core/constraint_validators/test_node_grouped_uniqueness.py b/backend/tests/unit/core/constraint_validators/test_node_grouped_uniqueness.py index 0ba788198c..bbd2cbeed0 100644 --- a/backend/tests/unit/core/constraint_validators/test_node_grouped_uniqueness.py +++ b/backend/tests/unit/core/constraint_validators/test_node_grouped_uniqueness.py @@ -75,6 +75,41 @@ async def test_uniqueness_constraint_conflict_two_attribute( with pytest.raises(ValidationError, match="Violates uniqueness constraint 'name-color'"): await self.__call_system_under_test(db=db, branch=default_branch, node=car_accord_main) + async def test_uniqueness_constraint_no_conflict_attribute_enum( + self, + db: InfrahubDatabase, + default_branch: Branch, + car_accord_main: Node, + car_camry_main: Node, + car_volt_main: Node, + ): + car_schema = registry.schema.get("TestCar", branch=default_branch, duplicate=False) + car_schema.uniqueness_constraints = [["nbr_seats__value", "name__value"]] + attr = car_schema.get_attribute("nbr_seats") + attr.optional = False + attr.enum = [2, 4, 5, 7] + + await self.__call_system_under_test(db=db, branch=default_branch, node=car_accord_main) + + async def test_uniqueness_constraint_conflict_attribute_enum( + self, + db: InfrahubDatabase, + default_branch: Branch, + car_accord_main: Node, + car_camry_main: Node, + car_volt_main: Node, + ): + car_schema = registry.schema.get("TestCar", branch=default_branch, duplicate=False) + attr = car_schema.get_attribute("nbr_seats") + attr.optional = False + attr.enum = [2, 4, 5, 7] + + car_accord_main.name.value = "camry" + car_accord_main.get_schema().uniqueness_constraints = [["nbr_seats__value", "name__value"]] + + with pytest.raises(ValidationError, match="Violates uniqueness constraint 'nbr_seats-name'"): + await self.__call_system_under_test(db=db, branch=default_branch, node=car_accord_main) + async def test_uniqueness_constraint_no_conflict_one_relationship( self, db: InfrahubDatabase, default_branch: Branch, car_person_generics_data_simple ): diff --git a/changelog/5132.fixed.md b/changelog/5132.fixed.md new file mode 100644 index 0000000000..692ac80f43 --- /dev/null +++ b/changelog/5132.fixed.md @@ -0,0 +1 @@ +Fix uniqueness constraint check with enum based attributes \ No newline at end of file