Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RuntimeError when re-ordering filters within an Alert Profiles filter group #2980

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/2979.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix crash bug when reordering filters within a filter group in Alert Profiles
2 changes: 1 addition & 1 deletion python/nav/web/alertprofiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,7 @@ def filter_group_addfilter(request):
def filter_group_remove_or_move_filter(request):
"""Deletes or moves around a filter within a filter group"""
post = request.POST.copy()
for name in post:
for name in request.POST:
if name.find("=") != -1:
attribute, value = name.split("=")
del post[name]
Expand Down
17 changes: 17 additions & 0 deletions tests/integration/web/alertprofiles_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,23 @@ def test_alertprofiles_remove_filter_group(self, db, client, dummy_filter_group)
assert dummy_filter_group.name in smart_str(response.content)
assert FilterGroup.objects.filter(pk=dummy_filter_group.pk).count() == 1

def test_alertprofiles_move_filter_within_group_should_not_crash(
self, db, client, dummy_filter_group
):
"""Regression test for #2979: Ensuring that pre-processing of request data
doesn't crash unexpectedly.
"""
url = reverse('alertprofiles-filter_groups-removefilter')
response = client.post(
url,
follow=True,
data={
"moveup=23": "Move+up",
"id": dummy_filter_group.id,
},
)
assert response.status_code in (200, 404)


#
# fixtures and helpers
Expand Down
Loading