From 184ec41df1108a4b71f6f2a0d2cffc8385d85786 Mon Sep 17 00:00:00 2001 From: Aaron McCarty Date: Tue, 3 Sep 2024 16:17:48 -0700 Subject: [PATCH] add diff conflict at the attribute level for value conflicts --- backend/infrahub/graphql/queries/diff/tree.py | 7 ++++++ .../unit/graphql/test_diff_tree_query.py | 24 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/backend/infrahub/graphql/queries/diff/tree.py b/backend/infrahub/graphql/queries/diff/tree.py index d7de246295..24585afbb6 100644 --- a/backend/infrahub/graphql/queries/diff/tree.py +++ b/backend/infrahub/graphql/queries/diff/tree.py @@ -8,6 +8,7 @@ from infrahub.core import registry from infrahub.core.constants import DiffAction, RelationshipCardinality +from infrahub.core.constants.database import DatabaseEdgeType from infrahub.core.diff.model.path import NameTrackingId from infrahub.core.diff.repository.repository import DiffRepository from infrahub.core.query.diff import DiffCountChanges @@ -75,6 +76,7 @@ class DiffAttribute(DiffSummaryCounts): path_identifier = String(required=True) properties = List(DiffProperty) contains_conflict = Boolean(required=True) + conflict = Field(ConflictDetails, required=False) class DiffSingleRelationship(DiffSummaryCounts): @@ -207,6 +209,10 @@ def to_diff_attribute( diff_properties = [ self.to_diff_property(enriched_property=e_prop, context=context) for e_prop in enriched_attribute.properties ] + conflict = None + for diff_prop in diff_properties: + if diff_prop.property_type == DatabaseEdgeType.HAS_VALUE.value and diff_prop.conflict: + conflict = diff_prop.conflict return DiffAttribute( name=enriched_attribute.name, last_changed_at=enriched_attribute.changed_at.obj, @@ -214,6 +220,7 @@ def to_diff_attribute( path_identifier=enriched_attribute.path_identifier, properties=diff_properties, contains_conflict=enriched_attribute.contains_conflict, + conflict=conflict, num_added=enriched_attribute.num_added, num_updated=enriched_attribute.num_updated, num_removed=enriched_attribute.num_removed, diff --git a/backend/tests/unit/graphql/test_diff_tree_query.py b/backend/tests/unit/graphql/test_diff_tree_query.py index 31c65fc0df..39aec40f3f 100644 --- a/backend/tests/unit/graphql/test_diff_tree_query.py +++ b/backend/tests/unit/graphql/test_diff_tree_query.py @@ -69,6 +69,18 @@ num_updated num_conflicts contains_conflict + conflict { + uuid + base_branch_action + base_branch_value + base_branch_changed_at + base_branch_label + diff_branch_action + diff_branch_value + diff_branch_changed_at + diff_branch_label + selected_branch + } properties { property_type last_changed_at @@ -353,6 +365,18 @@ async def test_diff_tree_one_attr_change( "num_conflicts": 1, "status": UPDATED_ACTION, "contains_conflict": True, + "conflict": { + "uuid": enriched_conflict.uuid, + "base_branch_action": UPDATED_ACTION, + "base_branch_value": "#fedcba", + "base_branch_changed_at": enriched_conflict.base_branch_changed_at.to_string(with_z=False), + "base_branch_label": None, + "diff_branch_action": UPDATED_ACTION, + "diff_branch_value": "#abcdef", + "diff_branch_changed_at": enriched_conflict.diff_branch_changed_at.to_string(with_z=False), + "diff_branch_label": None, + "selected_branch": GraphQLConfictSelection.DIFF_BRANCH.name, + }, "properties": [ { "property_type": "HAS_VALUE",