Skip to content

Commit

Permalink
models.py: Rule: Check content_object before accessing it
Browse files Browse the repository at this point in the history
We have noticed that deleting projects that contain rules throw an error
than can be seen on user's side as an "Internal Error!" page.

This occurs because the rule's "content_object.name" is trying to be
accessed after the project has been deleted, therefore "content_object"
is None and does not contain a "name" member.
  • Loading branch information
vincent-olivert-riera committed Jan 9, 2024
1 parent d0e5148 commit 88efde3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion promgen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,11 @@ class Meta:
ordering = ["content_type", "object_id", "name"]

def __str__(self):
return f"{self.name} [{self.content_object.name}]"
return (
f"{self.name}"
if self.content_object is None
else f"{self.name} [{self.content_object.name}]"
)

def get_absolute_url(self):
return reverse("rule-detail", kwargs={"pk": self.pk})
Expand Down

0 comments on commit 88efde3

Please sign in to comment.