@@ -1465,8 +1465,6 @@ def retrieve_question(
1465
1465
1466
1466
onderwerp_object = onderwerp_objecten [0 ]
1467
1467
1468
- zaak_with_api_group = None
1469
-
1470
1468
# fetch zaken for user
1471
1469
groups = ZGWApiGroupConfig .objects .filter (
1472
1470
klant_backend = KlantenServiceType .OPENKLANT2 .value
@@ -1480,17 +1478,22 @@ def retrieve_question(
1480
1478
)
1481
1479
return self ._build_question_dto (question_ok2 = question , user = user ), None
1482
1480
1483
- # find the unique zaak for the question
1481
+ # find the unique zaak + relevant api client for the question
1484
1482
zaken_for_question = []
1483
+ clients = []
1485
1484
for response in truthy_responses :
1486
1485
# discard the client for determining the api_group; we only need the zaak
1487
1486
zaken = response .result
1487
+ client = response .client
1488
1488
zaken_filtered = filter (
1489
1489
lambda z : z .identificatie
1490
1490
== onderwerp_object ["onderwerpobjectidentificator" ]["objectId" ],
1491
1491
zaken ,
1492
1492
)
1493
1493
zaken_for_question .extend (zaken_filtered )
1494
+ clients .append (client )
1495
+
1496
+ # sanity checks
1494
1497
if not zaken_for_question :
1495
1498
logger .info (
1496
1499
"Could not find zaak corresponding to question %s" ,
@@ -1503,10 +1506,18 @@ def retrieve_question(
1503
1506
question .question_kcm_uuid ,
1504
1507
)
1505
1508
return self ._build_question_dto (question_ok2 = question , user = user ), None
1509
+ if len (clients ) > 1 :
1510
+ logger .error ("Found one zaak in multiple backends" )
1511
+ return self ._build_question_dto (question_ok2 = question , user = user ), None
1512
+
1513
+ group = ZGWApiGroupConfig .objects .resolve_group_from_hints (client = clients [0 ])
1514
+ zaak_with_api_group = ZaakWithApiGroup (
1515
+ zaak = zaken_for_question [0 ], api_group = group
1516
+ )
1506
1517
1507
1518
return (
1508
1519
self ._build_question_dto (question_ok2 = question , user = user ),
1509
- zaken_for_question [ 0 ] ,
1520
+ zaak_with_api_group ,
1510
1521
)
1511
1522
1512
1523
def _build_question_dtos (
0 commit comments