Skip to content

Commit

Permalink
[BUGFIX] Fix testing Rule query before saving #510
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-olivert-riera authored May 16, 2024
2 parents fc96e6a + 482e350 commit 88cba05
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions promgen/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,13 @@ class RuleTest(LoginRequiredMixin, View):
def post(self, request, pk):
if pk == 0:
rule = models.Rule()
# 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
rule.set_object(request.POST["content_type"], request.POST["object_id"])
else:
rule = get_object_or_404(models.Rule, id=pk)
Expand Down

0 comments on commit 88cba05

Please sign in to comment.