diff --git a/backend/infrahub/core/models.py b/backend/infrahub/core/models.py index b8aab8d4c3..54e2358715 100644 --- a/backend/infrahub/core/models.py +++ b/backend/infrahub/core/models.py @@ -529,9 +529,12 @@ def _get_updated_list_value(self, field_name: str, attr_local: list[Any], attr_o return attr_other + def _get_field_names_for_diff(self) -> list[str]: + return list(self.model_fields.keys()) + def diff(self, other: Self) -> HashableModelDiff: in_both, local_only, other_only = compare_lists( - list1=list(self.model_fields.keys()), list2=list(other.model_fields.keys()) + list1=self._get_field_names_for_diff(), list2=other._get_field_names_for_diff() ) diff_result = HashableModelDiff(added=dict.fromkeys(local_only), removed=dict.fromkeys(other_only)) diff --git a/backend/infrahub/core/schema/generic_schema.py b/backend/infrahub/core/schema/generic_schema.py index 223ac7517a..4ead1f9d32 100644 --- a/backend/infrahub/core/schema/generic_schema.py +++ b/backend/infrahub/core/schema/generic_schema.py @@ -12,8 +12,6 @@ class GenericSchema(GeneratedGenericSchema): """A Generic can be either an Interface or a Union depending if there are some Attributes or Relationships defined.""" - _exclude_from_hash: list[str] = ["used_by", "attributes", "relationships"] - @property def is_node_schema(self) -> bool: return False @@ -35,3 +33,8 @@ def get_hierarchy_schema(self, db: InfrahubDatabase, branch: Optional[Union[Bran def get_labels(self) -> list[str]: """Return the labels for this object""" return [self.kind] + + def _get_field_names_for_diff(self) -> list[str]: + """Exclude used_by from the diff for generic nodes""" + fields = super()._get_field_names_for_diff() + return [field for field in fields if field not in ["used_by"]]