Skip to content

Commit

Permalink
[BUGFIX] Fix for foreign key check regarding m2m #497
Browse files Browse the repository at this point in the history
  • Loading branch information
kfdm authored Apr 17, 2024
2 parents 600732c + 2761419 commit 69ba806
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions promgen/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ def clean(self):
super().clean()
rule = models.Rule(**self.cleaned_data)

# In Django https://code.djangoproject.com/ticket/19580, some of the
# foreign key checks got stricter. We sets pk to 0 here so that it passes
# django's m2m/foreign key checks, but marks for us that it's a temporary
# rule that doesn't actually exist.
# We'll likely want to rework this assumption when we move to a different
# promql check
rule.pk = 0

# Make sure we pull in our labels and annotations for
# testing if needed
# See django docs on cached_property
Expand Down
4 changes: 2 additions & 2 deletions promgen/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,9 +423,9 @@ class Meta:

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

def get_absolute_url(self):
Expand Down

0 comments on commit 69ba806

Please sign in to comment.