Skip to content

Commit 2c9a961

Browse files
authored
Merge pull request #715 from maykinmedia/fix/712-broken-filter
[#712] Broken filter not_in_destruction_list_except
2 parents 818f456 + 144a62a commit 2c9a961

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

backend/src/openarchiefbeheer/zaken/api/views.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,15 @@ def _retrieve_zaaktypen(self, request):
5858
if not is_valid:
5959
raise ValidationError(filterset.errors)
6060

61-
zaaktypen = filterset.qs.distinct("_expand__zaaktype__url").values_list(
61+
# FIXME issue #712
62+
# The filter not_in_destruction_list_except does an order_by on "in_exception_list" and "pk"
63+
# However, we cannot combine a distinct and an order_by on different fields.
64+
# So we add an order by on "_expand__zaaktype__url" as a bandaid fix until we fix the ordering in the filter
65+
qs = filterset.qs
66+
if filterset.data.get("not_in_destruction_list_except"):
67+
qs = qs.order_by("_expand__zaaktype__url")
68+
69+
zaaktypen = qs.distinct("_expand__zaaktype__url").values_list(
6270
"_expand__zaaktype", flat=True
6371
)
6472
zaaktypen_choices = format_zaaktype_choices(zaaktypen)

backend/src/openarchiefbeheer/zaken/tests/test_views.py

+16
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,22 @@ def test_retrieve_zaaktypen_choices_invalid_filters(self):
439439
response.json()["inDestructionList"][0], _("Enter a valid UUID.")
440440
)
441441

442+
def test_retrieve_zaaktypen_choices_not_in_destruction_list_except(self):
443+
user = UserFactory.create()
444+
445+
ZaakFactory.create()
446+
447+
destruction_list = DestructionListFactory.create()
448+
449+
self.client.force_authenticate(user=user)
450+
url = reverse("api:retrieve-zaaktypen-choices")
451+
452+
response = self.client.post(
453+
url, data={"not_in_destruction_list_except": destruction_list.uuid}
454+
)
455+
456+
self.assertEqual(response.status_code, status.HTTP_200_OK)
457+
442458

443459
class SelectielijstklasseChoicesViewTests(ClearCacheMixin, APITestCase):
444460

0 commit comments

Comments
 (0)