Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Changelog

## [Unreleased](https://github.com/openfga/python-sdk/compare/v0.9.2...HEAD)
## [Unreleased](https://github.com/openfga/python-sdk/compare/v0.9.3...HEAD)
- fix: ListRelations should not swallow errors (#183)
- feat: feat: support List Stores name filter (#181)

### [0.9.3](https://github.com/openfga/python-sdk/compare/v0.9.2...v0.9.3) (2025-03-26)

- feat: feat: support List Stores name filter (#181)
- fix: urllib3 compatibility < v2 (#179)

### [0.9.2](https://github.com/openfga/python-sdk/compare/v0.9.1...v0.9.2) (2025-03-25)
Expand Down
14 changes: 14 additions & 0 deletions openfga_sdk/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,13 @@ def options_to_transaction_info(
return WriteTransactionOpts()


def _check_errored(response: ClientBatchCheckClientResponse):
"""
Helper function to return whether the response is errored
"""
return response.error is not None


def _check_allowed(response: ClientBatchCheckClientResponse):
"""
Helper function to return whether the response is check is allowed
Expand Down Expand Up @@ -972,6 +979,13 @@ async def list_relations(
for i in body.relations
]
result = await self.client_batch_check(request_body, options)

# filter out any errored responses and raise the first error
errored_result_iterator = filter(_check_errored, result)
errored_result_list = list(errored_result_iterator)
if len(errored_result_list) > 0:
raise errored_result_list[0].error

# need to filter with the allowed response
result_iterator = filter(_check_allowed, result)
result_list = list(result_iterator)
Expand Down
14 changes: 14 additions & 0 deletions openfga_sdk/sync/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ def options_to_transaction_info(
return WriteTransactionOpts()


def _check_errored(response: ClientBatchCheckClientResponse):
"""
Helper function to return whether the response is errored
"""
return response.error is not None


def _check_allowed(response: ClientBatchCheckClientResponse):
"""
Helper function to return whether the response is check is allowed
Expand Down Expand Up @@ -971,6 +978,13 @@ def list_relations(
for i in body.relations
]
result = self.client_batch_check(request_body, options)

# filter out any errored responses and raise the first error
errored_result_iterator = filter(_check_errored, result)
errored_result_list = list(errored_result_iterator)
if len(errored_result_list) > 0:
raise errored_result_list[0].error

# need to filter with the allowed response
result_iterator = filter(_check_allowed, result)
result_list = list(result_iterator)
Expand Down
21 changes: 21 additions & 0 deletions test/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2875,6 +2875,27 @@ async def test_list_relations_unauthorized(self, mock_request):
mock_request.assert_called()
await api_client.close()

@patch.object(rest.RESTClientObject, "request")
async def test_list_relations_errored(self, mock_request):
"""Test case for list relations with undefined exception"""

mock_request.side_effect = ValueError()
configuration = self.configuration
configuration.store_id = store_id
async with OpenFgaClient(configuration) as api_client:
with self.assertRaises(ValueError):
await api_client.list_relations(
body=ClientListRelationsRequest(
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relations=["reader", "owner", "viewer"],
object="document:2021-budget",
),
options={"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"},
)

mock_request.assert_called()
await api_client.close()

@patch.object(rest.RESTClientObject, "request")
async def test_list_users(self, mock_request):
"""
Expand Down
21 changes: 21 additions & 0 deletions test/sync/client/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2878,6 +2878,27 @@ def test_list_relations_unauthorized(self, mock_request):
mock_request.assert_called()
api_client.close()

@patch.object(rest.RESTClientObject, "request")
def test_list_relations_errored(self, mock_request):
"""Test case for list relations with undefined exception"""

mock_request.side_effect = ValueError()
configuration = self.configuration
configuration.store_id = store_id
with OpenFgaClient(configuration) as api_client:
with self.assertRaises(ValueError):
api_client.list_relations(
body=ClientListRelationsRequest(
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
relations=["reader", "owner", "viewer"],
object="document:2021-budget",
),
options={"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"},
)

mock_request.assert_called()
api_client.close()

@patch.object(rest.RESTClientObject, "request")
def test_list_users(self, mock_request):
"""
Expand Down
Loading