Skip to content

Commit

Permalink
Avoid database query on import
Browse files Browse the repository at this point in the history
The "choices"-attribute for the field "sourceSystemIds" of "IncidentFilterForm"
used to query the database on import. The query is now deferred to the
initialization of the form instance.
  • Loading branch information
elfjes authored Feb 17, 2025
1 parent 9f6df5d commit d995b72
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/1176.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not run database query when importing IncidentFormFilter
2 changes: 1 addition & 1 deletion src/argus/htmx/incident/filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class IncidentFilterForm(forms.Form):
attrs={"placeholder": "select sources..."},
partial_get=None,
),
choices=tuple(SourceSystem.objects.values_list("id", "name")),
required=False,
label="Sources",
)
Expand All @@ -60,6 +59,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# mollify tests
self.fields["sourceSystemIds"].widget.partial_get = reverse("htmx:incident-filter")
self.fields["sourceSystemIds"].choices = tuple(SourceSystem.objects.values_list("id", "name"))

def _tristate(self, onkey, offkey):
on = self.cleaned_data.get(onkey, None)
Expand Down

0 comments on commit d995b72

Please sign in to comment.