Skip to content

Commit

Permalink
🐛 [#1904] Fix Case list crashing due to reused Statustypen
Browse files Browse the repository at this point in the history
task: https://taiga.maykinmedia.nl/project/open-inwoner/task/1904

if the ZGW APIs reuse StatusTypen for different ZaakTypen, we end up with multiple `ZaakTypeStatusTypeConfig` that have the same `statustype_url`, which led to errors when retrieving these configs. To fix this we explicitly filter for the correct `ZaakTypeConfig` as well
  • Loading branch information
stevenbal authored and alextreme committed Dec 4, 2023
1 parent bbc1a2a commit 899fa8c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/open_inwoner/openzaak/api_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def process_data(self) -> dict:
"current_status": status_translate.from_glom(
self, "status.statustype.omschrijving", default=""
),
"zaaktype_config": getattr(self, "zaaktype_config", None),
"statustype_config": getattr(self, "statustype_config", None),
"case_type": "Zaak",
}
Expand Down
23 changes: 20 additions & 3 deletions src/open_inwoner/openzaak/cases.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .api_models import Resultaat, Rol, Status, Zaak, ZaakInformatieObject
from .catalog import fetch_single_case_type, fetch_single_status_type
from .clients import build_client
from .models import OpenZaakConfig, ZaakTypeStatusTypeConfig
from .models import OpenZaakConfig, ZaakTypeConfig, ZaakTypeStatusTypeConfig
from .utils import is_zaak_visible

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -403,6 +403,21 @@ def resolve_status_type(case: Zaak) -> None:
case.status.statustype = fetch_single_status_type(statustype_url)


def add_zaak_type_config(case: Zaak) -> None:
"""
Add `ZaakTypeConfig` corresponding to the zaaktype type url of the case
Note: must be called after `resolve_zaak_type` since we're using the `uuid` and
`identificatie` from `case.zaaktype`
"""
try:
case.zaaktype_config = ZaakTypeConfig.objects.filter_case_type(
case.zaaktype
).get()
except ZaakTypeConfig.DoesNotExist:
pass


def add_status_type_config(case: Zaak) -> None:
"""
Add `ZaakTypeStatusTypeConfig` corresponding to the status type url of the case
Expand All @@ -412,9 +427,10 @@ def add_status_type_config(case: Zaak) -> None:
"""
try:
case.statustype_config = ZaakTypeStatusTypeConfig.objects.get(
statustype_url=case.status.statustype.url
zaaktype_config=case.zaaktype_config,
statustype_url=case.status.statustype.url,
)
except ZaakTypeStatusTypeConfig.DoesNotExist:
except (AttributeError, ZaakTypeStatusTypeConfig.DoesNotExist):
pass


Expand All @@ -433,6 +449,7 @@ def preprocess_data(cases: list[Zaak]) -> list[Zaak]:
for case in cases:
resolve_status(case)
resolve_status_type(case)
add_zaak_type_config(case)
add_status_type_config(case)

cases.sort(key=lambda case: case.startdatum, reverse=True)
Expand Down

0 comments on commit 899fa8c

Please sign in to comment.