Skip to content

Commit

Permalink
Avoid "id" attribute to sort Structure.grouping
Browse files Browse the repository at this point in the history
DictLikes of ComponentList will not have this attribute.
  • Loading branch information
khaeru committed Jan 10, 2024
1 parent 6668c49 commit 85f7f82
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions sdmx/model/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1146,13 +1146,14 @@ def replace_grouping(self, cl: ComponentList) -> None:
setattr(self, field.name, cl)

def compare(self, other: "Structure", strict: bool = True) -> bool:
from operator import attrgetter
# DictLike of ComponentList will not have an "id" attribute
def _key(item) -> str:
return getattr(item, "id", str(type(item)))

return all(
s.compare(o, strict)
for s, o in zip(
sorted(self.grouping, key=attrgetter("id")),
sorted(other.grouping, key=attrgetter("id")),
sorted(self.grouping, key=_key), sorted(other.grouping, key=_key)
)
)

Expand Down

0 comments on commit 85f7f82

Please sign in to comment.