Skip to content

Commit

Permalink
Exclude used_by from the diff but not the hash
Browse files Browse the repository at this point in the history
  • Loading branch information
dgarros committed Dec 13, 2024
1 parent 8d29162 commit f46f33d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
5 changes: 4 additions & 1 deletion backend/infrahub/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
7 changes: 5 additions & 2 deletions backend/infrahub/core/schema/generic_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]]

0 comments on commit f46f33d

Please sign in to comment.