Skip to content

Commit

Permalink
fix(generic): check for attribute id before using it
Browse files Browse the repository at this point in the history
Some models do not have an `id` attribute, therefore it makes sense to
check for its existence before using it in the __repr__ string.

Closes: #1450
  • Loading branch information
b1rger committed Nov 27, 2024
1 parent 624d74a commit 45b4e63
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion apis_core/generic/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

class GenericModel:
def __repr__(self):
return super().__repr__() + f" (ID: {self.id})"
if id := getattr(self, "id", None):
return super().__repr__() + f" (ID: {id})"
return super().__repr__()

@classmethod
def get_listview_url(cls):
Expand Down

0 comments on commit 45b4e63

Please sign in to comment.