From 9e8399a4fdd2da698a14dab5518ba2aba8b6ea57 Mon Sep 17 00:00:00 2001 From: Ewan Harris Date: Wed, 18 Dec 2024 15:56:15 +0000 Subject: [PATCH] refactor: change example to use a for loop rather than direct access Helps show the correlation_id use --- example/example1/example1.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/example/example1/example1.py b/example/example1/example1.py index cbae1263..30934f73 100644 --- a/example/example1/example1.py +++ b/example/example1/example1.py @@ -19,6 +19,7 @@ Usersets, UserTypeFilter, WriteAuthorizationModelRequest, + telemetry, ) from openfga_sdk.client.models import ( ClientAssertion, @@ -283,7 +284,7 @@ async def main(): relation="viewer", object="document:0192ab2a-d83f-756d-9397-c5ed9f3cb69a", context=dict(ViewCount=100), - correlation_id=anne_cor_id, + correlation_id=anne_cor_id, # correlation_id is an optional parameter, the SDK will insert a value if not provided. ), ClientBatchCheckItem( user="user:bob", @@ -294,8 +295,12 @@ async def main(): ] ) ) - print(f"Anne allowed: {response.result[0].allowed}") - print(f"Bob allowed: {response.result[1].allowed}") + + for result in response.result: + if result.correlation_id == anne_cor_id: + print(f"Anne allowed: {result.allowed}") + else: + print(f"{result.request.user} allowed: {result.allowed}") # List objects with context print("Listing objects for access with context")