Skip to content

Fix issue where aiohttp.ClientResponse data wasn't being awaited on #197

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cmbernard333
Copy link

@cmbernard333 cmbernard333 commented Jun 5, 2025

Fixes issue #184 where aiohttp.ClientResponse data wasn't being awaited on. Credit to @extreme4all and @demetere for doing the actual investigation work here.

Description

Added awaiting for the response data inside of the exception handler so that it is safe to read the response status.

References

Review Checklist

  • I have clicked on "allow edits by maintainers".
  • I have added documentation for new/changed functionality in this PR or in a PR to openfga.dev [Provide a link to any relevant PRs in the references section above]
  • The correct base branch is being used, if not main
  • I have added tests to validate that the change in functionality is working as expected

@cmbernard333 cmbernard333 requested a review from a team as a code owner June 5, 2025 21:53
Copy link

linux-foundation-easycla bot commented Jun 5, 2025

CLA Signed


The committers listed above are authorized under a signed CLA.

@cmbernard333 cmbernard333 changed the title Fix issue where aiohttp.ClientResponse data wasn't being awaited on d… Fix issue where aiohttp.ClientResponse data wasn't being awaited on Jun 5, 2025
@cmbernard333
Copy link
Author

@extreme4all and @demetere let me know if I missed something. This functionality is super important to handle http statuses correctly.

@demetere
Copy link

demetere commented Jun 7, 2025

@cmbernard333 The two-line change itself is indeed straightforward, but the main challenge I've been facing is writing a test case that captures the issue. Right now, the tests pass both with and without the change, which suggests we're missing coverage for that edge case. I'm currently digging into the existing tests to understand what's already covered and where a new test would best fit to reflect the problem we're addressing. That's why I haven’t opened a PR just yet.

@cmbernard333
Copy link
Author

cmbernard333 commented Jun 7, 2025

@cmbernard333 The two-line change itself is indeed straightforward, but the main challenge I've been facing is writing a test case that captures the issue. Right now, the tests pass both with and without the change, which suggests we're missing coverage for that edge case. I'm currently digging into the existing tests to understand what's already covered and where a new test would best fit to reflect the problem we're addressing. That's why I haven’t opened a PR just yet.

Interesting. I can consistently make it fail, prior to any changes, by passing bad data to the /check api when using it in asynchronous mode in my own code. Let me see if I can’t pull a test together.

@cmbernard333
Copy link
Author

After reviewing the tests in the repo, and unless I'm missing something entirely, there doesn't appear to be a good way to test this inside the repo itself since everything appears to be mocked. I can repeatedly reproduce this with the openfga python-sdk talking to a local openfga instance just by passing bad data to /check. It will consistently throw an exception with the message AttributeError: 'ClientResponse' object has no attribute 'data'. This makes getting errors from the python-sdk non-trivial.

Any proposal here on testing it properly is appreciated.

@cmbernard333
Copy link
Author

@demetere one more note: the failure is reproducible most when using async, hence the need to check for aiohttp.ClientResponse. Does that help us narrow down a test case?

@cmbernard333
Copy link
Author

@cmbernard333 The two-line change itself is indeed straightforward, but the main challenge I've been facing is writing a test case that captures the issue. Right now, the tests pass both with and without the change, which suggests we're missing coverage for that edge case. I'm currently digging into the existing tests to understand what's already covered and where a new test would best fit to reflect the problem we're addressing. That's why I haven’t opened a PR just yet.

I know I am being annoying. Its annoying this occurs constantly for me in my testing. It is definitely not an edge case when running with async. I can easily reproduce it with the SDK via the following:

    read_response: ReadResponse = await openfga_client.read(
        body=ReadRequestTupleKey(
            user="user:some-id",
            relation="admin",
            object="bad_object:some-id",
        )
    )

Then it produces this stack trace

    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'

@demetere
Copy link

Sadly I do not have any leads on that, that was the sole reason for not opening PR from my side, Let ask the opinion of maintainers

@RRRajput
Copy link

Is there any update on this one?

@dyeam0
Copy link
Member

dyeam0 commented Jun 16, 2025

Hi all. Thanks @cmbernard333 and @demetere for really digging into this issue. During our backlog review this week, we can assign someone to help and get more eyes on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants