Skip to content

Commit

Permalink
Fix for foreign key check regarding m2m
Browse files Browse the repository at this point in the history
Some of the behavior changed between Django 3.2 and 4.2 so we make a fix
here to get around it. Also add the rule pk to the __str__ for us to use
while debugging
  • Loading branch information
kfdm committed Apr 17, 2024
1 parent 600732c commit 2761419
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 2761419

Please sign in to comment.