diff --git a/openfga_sdk/client/client.py b/openfga_sdk/client/client.py index 40d8fa9..38b7aae 100644 --- a/openfga_sdk/client/client.py +++ b/openfga_sdk/client/client.py @@ -706,7 +706,7 @@ async def batch_check(self, body: ClientBatchCheckRequest, options=None): elif isinstance(options["max_batch_size"], int): max_batch_size = options["max_batch_size"] - check_to_id: dict[str, ClientBatchCheckItem] = {} + id_to_check: dict[str, ClientBatchCheckItem] = {} def track_and_transform(checks): transformed = [] @@ -714,10 +714,12 @@ def track_and_transform(checks): if check.correlation_id is None: check.correlation_id = str(uuid.uuid4()) - if check.correlation_id in check_to_id: - raise FgaValidationException("Duplicate correlation_id provided") + if check.correlation_id in id_to_check: + raise FgaValidationException( + f"Duplicate correlation_id ({check.correlation_id}) provided" + ) - check_to_id[check.correlation_id] = check + id_to_check[check.correlation_id] = check transformed.append(construct_batch_item(check)) return transformed @@ -733,7 +735,7 @@ def track_and_transform(checks): sem = asyncio.Semaphore(max_parallel_requests) def map_response(id, result): - check = check_to_id[id] + check = id_to_check[id] return ClientBatchCheckSingleResponse( allowed=result.allowed, request=check, diff --git a/openfga_sdk/sync/client/client.py b/openfga_sdk/sync/client/client.py index f4bd3f4..07bddcc 100644 --- a/openfga_sdk/sync/client/client.py +++ b/openfga_sdk/sync/client/client.py @@ -692,7 +692,7 @@ def batch_check(self, body: ClientBatchCheckRequest, options=None): elif isinstance(options["max_batch_size"], int): max_batch_size = options["max_batch_size"] - check_to_id: dict[str, ClientBatchCheckItem] = {} + id_to_check: dict[str, ClientBatchCheckItem] = {} def track_and_transform(checks): transformed = [] @@ -700,10 +700,12 @@ def track_and_transform(checks): if check.correlation_id is None: check.correlation_id = str(uuid.uuid4()) - if check.correlation_id in check_to_id: - raise FgaValidationException("Duplicate correlation_id provided") + if check.correlation_id in id_to_check: + raise FgaValidationException( + f"Duplicate correlation_id ({check.correlation_id}) provided" + ) - check_to_id[check.correlation_id] = check + id_to_check[check.correlation_id] = check transformed.append(construct_batch_item(check)) return transformed @@ -716,7 +718,7 @@ def track_and_transform(checks): ] def map_response(id, result): - check = check_to_id[id] + check = id_to_check[id] return ClientBatchCheckSingleResponse( allowed=result.allowed, request=check, diff --git a/test/client/client_test.py b/test/client/client_test.py index fa16fe7..70f6850 100644 --- a/test/client/client_test.py +++ b/test/client/client_test.py @@ -2414,11 +2414,14 @@ async def test_batch_check_errors_dupe_cor_id(self): configuration = self.configuration configuration.store_id = store_id async with OpenFgaClient(configuration) as api_client: - with self.assertRaises(FgaValidationException): + with self.assertRaises(FgaValidationException) as error: await api_client.batch_check( body=body, options={"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"}, ) + self.assertEqual( + "Duplicate correlation_id (1) provided", str(error.exception) + ) await api_client.close() @patch.object(rest.RESTClientObject, "request") diff --git a/test/sync/client/client_test.py b/test/sync/client/client_test.py index 5d7ca86..292e78b 100644 --- a/test/sync/client/client_test.py +++ b/test/sync/client/client_test.py @@ -2416,11 +2416,14 @@ def test_batch_check_errors_dupe_cor_id(self): configuration = self.configuration configuration.store_id = store_id with OpenFgaClient(configuration) as api_client: - with self.assertRaises(FgaValidationException): + with self.assertRaises(FgaValidationException) as error: api_client.batch_check( body=body, options={"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"}, ) + self.assertEqual( + "Duplicate correlation_id (1) provided", str(error.exception) + ) api_client.close() @patch.object(rest.RESTClientObject, "request")