Skip to content

Commit

Permalink
Merge pull request #1601 from open-zaak/feature/1584-fix-500-autorisa…
Browse files Browse the repository at this point in the history
…ties-error

✨[#1584] fix autorisaties 500 error when related object deleted
  • Loading branch information
Coperh committed Apr 5, 2024
2 parents 6bad93f + e8be4f4 commit 9420204
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1009,3 +1009,22 @@ def test_remove_iotype_with_autorisaties_linked(self):
self.assertEqual(response.status_code, 200)
initial_data = response.context["formdata"]
self.assertEqual(len(initial_data), 2) # 1 empty form, 1 unrelated auth spec

@tag("gh-1584")
def test_related_object_does_not_exist(self):
"""
Assert that the autorisaties view does not crash
if an autorisatie fails to delete after its related object is deleted.
"""

AutorisatieFactory.create(
applicatie=self.applicatie,
component=ComponentTypes.drc,
scopes=["documenten.lezen"],
max_vertrouwelijkheidaanduiding=VertrouwelijkheidsAanduiding.openbaar,
informatieobjecttype="http://testserver/url_to_nowhere/00000000-0000-0000-0000-000000000000",
)

# check that the admin page does not crash
response = self.client.get(self.url)
self.assertEqual(response.status_code, 200)
7 changes: 5 additions & 2 deletions src/openzaak/components/autorisaties/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ def _get_related_object(model: ModelBase, url: str) -> Optional[RelatedTypeObjec
if url == "":
return None
uuid = url.rsplit("/")[-1]
obj = model.objects.get(uuid=uuid)
return obj
try:
obj = model.objects.get(uuid=uuid)
return obj
except model.DoesNotExist:
return None


def get_related_object(autorisatie: Autorisatie) -> Optional[RelatedTypeObject]:
Expand Down

0 comments on commit 9420204

Please sign in to comment.