Skip to content

Commit 7e92a24

Browse files
committed
refactor: rename variable, improve duplicate id error message
1 parent 79509c1 commit 7e92a24

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

openfga_sdk/client/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -706,18 +706,18 @@ async def batch_check(self, body: ClientBatchCheckRequest, options=None):
706706
elif isinstance(options["max_batch_size"], int):
707707
max_batch_size = options["max_batch_size"]
708708

709-
check_to_id: dict[str, ClientBatchCheckItem] = {}
709+
id_to_check: dict[str, ClientBatchCheckItem] = {}
710710

711711
def track_and_transform(checks):
712712
transformed = []
713713
for check in checks:
714714
if check.correlation_id is None:
715715
check.correlation_id = str(uuid.uuid4())
716716

717-
if check.correlation_id in check_to_id:
718-
raise FgaValidationException("Duplicate correlation_id provided")
717+
if check.correlation_id in id_to_check:
718+
raise FgaValidationException(f"Duplicate correlation_id ({check.correlation_id}) provided")
719719

720-
check_to_id[check.correlation_id] = check
720+
id_to_check[check.correlation_id] = check
721721

722722
transformed.append(construct_batch_item(check))
723723
return transformed
@@ -733,7 +733,7 @@ def track_and_transform(checks):
733733
sem = asyncio.Semaphore(max_parallel_requests)
734734

735735
def map_response(id, result):
736-
check = check_to_id[id]
736+
check = id_to_check[id]
737737
return ClientBatchCheckSingleResponse(
738738
allowed=result.allowed,
739739
request=check,

openfga_sdk/sync/client/client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -692,18 +692,18 @@ def batch_check(self, body: ClientBatchCheckRequest, options=None):
692692
elif isinstance(options["max_batch_size"], int):
693693
max_batch_size = options["max_batch_size"]
694694

695-
check_to_id: dict[str, ClientBatchCheckItem] = {}
695+
id_to_check: dict[str, ClientBatchCheckItem] = {}
696696

697697
def track_and_transform(checks):
698698
transformed = []
699699
for check in checks:
700700
if check.correlation_id is None:
701701
check.correlation_id = str(uuid.uuid4())
702702

703-
if check.correlation_id in check_to_id:
704-
raise FgaValidationException("Duplicate correlation_id provided")
703+
if check.correlation_id in id_to_check:
704+
raise FgaValidationException(f"Duplicate correlation_id ({check.correlation_id}) provided")
705705

706-
check_to_id[check.correlation_id] = check
706+
id_to_check[check.correlation_id] = check
707707

708708
transformed.append(construct_batch_item(check))
709709
return transformed
@@ -716,7 +716,7 @@ def track_and_transform(checks):
716716
]
717717

718718
def map_response(id, result):
719-
check = check_to_id[id]
719+
check = id_to_check[id]
720720
return ClientBatchCheckSingleResponse(
721721
allowed=result.allowed,
722722
request=check,

test/client/client_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2414,11 +2414,15 @@ async def test_batch_check_errors_dupe_cor_id(self):
24142414
configuration = self.configuration
24152415
configuration.store_id = store_id
24162416
async with OpenFgaClient(configuration) as api_client:
2417-
with self.assertRaises(FgaValidationException):
2417+
with self.assertRaises(FgaValidationException) as error:
24182418
await api_client.batch_check(
24192419
body=body,
24202420
options={"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"},
24212421
)
2422+
self.assertEqual(
2423+
"Duplicate correlation_id (1) provided",
2424+
str(error.exception)
2425+
)
24222426
await api_client.close()
24232427

24242428
@patch.object(rest.RESTClientObject, "request")

test/sync/client/client_test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,11 +2416,15 @@ def test_batch_check_errors_dupe_cor_id(self):
24162416
configuration = self.configuration
24172417
configuration.store_id = store_id
24182418
with OpenFgaClient(configuration) as api_client:
2419-
with self.assertRaises(FgaValidationException):
2419+
with self.assertRaises(FgaValidationException) as error:
24202420
api_client.batch_check(
24212421
body=body,
24222422
options={"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"},
24232423
)
2424+
self.assertEqual(
2425+
"Duplicate correlation_id (1) provided",
2426+
str(error.exception)
2427+
)
24242428
api_client.close()
24252429

24262430
@patch.object(rest.RESTClientObject, "request")

0 commit comments

Comments
 (0)