Skip to content

Error handling broken #199

@Oscmage

Description

@Oscmage

Checklist

  • I have looked into the README and have not found a suitable solution or answer.
  • I have looked into the documentation and have not found a suitable solution or answer.
  • I have searched the issues and have not found a suitable solution or answer.
  • I have upgraded to the latest version of OpenFGA and the issue still persists.
  • I have searched the Slack community and have not found a suitable solution or answer.
  • I agree to the terms within the OpenFGA Code of Conduct.

Description

See original reach out in OpenFGA slack channel here

Performing a write that fails (for example a bad request or duplicated tuple) results in the client raising an attribute error rather than providing the error in the response. See example below:

response = await self.client.write(
                ClientWriteRequest(
                    writes=[
                        ClientTuple(
                            user=f"{user_type}:{user_id}",
                            relation=relation,
                            object=f"{object_type}:{object_id}",
                        ),
                    ],
                ),
            )

Results in the traceback:

   response = await self.client.write(
../../.venv/lib/python3.13/site-packages/openfga_sdk/client/client.py:572: in write
    results = await self._write_with_transaction(body, options)
../../.venv/lib/python3.13/site-packages/openfga_sdk/client/client.py:535: in _write_with_transaction
    await self._api.write(
../../.venv/lib/python3.13/site-packages/openfga_sdk/api/open_fga_api.py:2692: in write
    return await self.write_with_http_info(body, **kwargs)
../../.venv/lib/python3.13/site-packages/openfga_sdk/api/open_fga_api.py:2825: in write_with_http_info
    return await self.api_client.call_api(
../../.venv/lib/python3.13/site-packages/openfga_sdk/api_client.py:601: in call_api
    return await self.__call_api(
../../.venv/lib/python3.13/site-packages/openfga_sdk/api_client.py:288: in __call_api
    response_data = await self.request(
../../.venv/lib/python3.13/site-packages/openfga_sdk/api_client.py:677: in request
    return await self.rest_client.request(
../../.venv/lib/python3.13/site-packages/openfga_sdk/rest.py:465: in request
    await self.handle_response_exception(raw_response)
../../.venv/lib/python3.13/site-packages/openfga_sdk/rest.py:283: in handle_response_exception
    raise ValidationException(http_resp=response)
../../.venv/lib/python3.13/site-packages/openfga_sdk/exceptions.py:187: in __init__
    super().__init__(status, reason, http_resp)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = ValidationException(), status = None, reason = None
http_resp = <ClientResponse(http://localhost:65044/stores/01JZ893BKZNSEDKAG85TYVH6JB/write) [400 Bad Request]>
<CIMultiDictProxy('...equest-Id': '6ec34b25-fa71-4d31-809e-b58faa5aa33b', 'Date': 'Thu, 03 Jul 2025 13:55:00 GMT', 'Content-Length': '308')>


    def __init__(self, status=None, reason=None, http_resp=None):
        if http_resp:
            try:
                headers = http_resp.headers.items()
            except AttributeError:
                headers = http_resp.getheaders().items()
    
            self.status = http_resp.status
            self.reason = http_resp.reason
>           self.body = http_resp.data
E           AttributeError: 'ClientResponse' object has no attribute 'data'

../../.venv/lib/python3.13/site-packages/openfga_sdk/exceptions.py:128: AttributeError

The python sdk version: 0.9.4.

This seems to also be the case for other methods.

Expectation

I'd expect that it would not raise and instead allow me to access something like

response.errors as the API works for singles or I'd get the exception to why the call failed.

Reproduction

configuration = openfga_sdk.ClientConfiguration(
        api_url=config.OPENFGA_API_URL,
        credentials=Credentials(
            method="api_token",
            configuration=CredentialConfiguration(
                api_token=config.OPENFGA_SECRET,
            ),
        ),
    )
client = OpenFgaClient(OpenFgaClientSDK(configuration))
response = await client.write(
                ClientWriteRequest(
                    writes=[
                        ClientTuple(
                            user=f"{user_type}:{user_id}",
                            relation=relation,
                            object=f"{object_type}:{object_id}",
                        ),
                    ],
                ),
            )

OpenFGA SDK version

0.9.4

OpenFGA version

v1.8.16

SDK Configuration

configuration = openfga_sdk.ClientConfiguration( api_url=config.OPENFGA_API_URL, credentials=Credentials( method="api_token", configuration=CredentialConfiguration( api_token=config.OPENFGA_SECRET, ), ), ) client = OpenFgaClient(OpenFgaClientSDK(configuration))

Logs

No response

References

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions