Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Getting an error coroutine 'AsyncRestClient._request_with_session' was never awaited #555

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

Closed
5 tasks done
chipxsd opened this issue Nov 22, 2023 · 3 comments · Fixed by #556
Closed
5 tasks done
Labels
bug This points to a verified bug in the code

Comments

@chipxsd
Copy link

chipxsd commented Nov 22, 2023

Checklist

  • I have looked into the Readme and Examples, and have not found a suitable solution or answer.
  • I have looked into the API 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 searched the Auth0 Community forums and have not found a suitable solution or answer.
  • I agree to the terms within the Auth0 Code of Conduct.

Description

I've been noticing some errors in our logs ever since we bumped the Auth0-python lib version to 4.6.0:

2023-11-21 23:42:35   File "/osiris/pkgs/osiris_api_service/providers/auth0/identity_provider_client.py", line 82, in _get_auth0_access_token
2023-11-21 23:42:35     return response["access_token"]
2023-11-21 23:42:35            ~~~~~~~~^^^^^^^^^^^^^^^^
2023-11-21 23:42:35 INFO:     169.254.1.1:28012 - "GET /organizations/5e220319-013b-****-****-2dfeb8ad7cf0/invitations HTTP/1.1" 200 OK
2023-11-21 23:42:36 TypeError: 'coroutine' object is not subscriptable
2023-11-21 23:44:42 sys:1: RuntimeWarning: coroutine 'AsyncRestClient._request_with_session' was never awaited
2023-11-21 23:44:42 RuntimeWarning: Enable tracemalloc to get the object allocation traceback

I don't have it captured in a test to reproduce it, but I'll share our authentication code.

Reproduction

AsyncGetToken = asyncify(authentication.GetToken)

...

    @property
    async def client(self) -> AsyncAuth0:
        """
        This property method returns an instance of AsyncAuth0. If the instance
        does not exist, it creates a new one using the domain and access
        token obtained from the _get_auth0_access_token method.
        """
        if self._client is None:
            auth0_token = await self._get_auth0_access_token()
            self._client = AsyncAuth0(self.domain, auth0_token)

        return self._client


    async def _get_auth0_access_token(self) -> str:
        """
        Performs the Auth0 authentication and returns the access token.
        """
        get_token = AsyncGetToken(self.domain, self.client_id, self.client_secret)
        response = await get_token.client_credentials_async(f"https://{self.domain}/api/v2/")

        return response["access_token"] # <--- fails here with TypeError: 'coroutine' object is not subscriptable

Additional context

No response

auth0-python version

4.6.0

Python version

3.11.4

@chipxsd chipxsd added the bug This points to a verified bug in the code label Nov 22, 2023
@chipxsd
Copy link
Author

chipxsd commented Nov 22, 2023

Not sure, but I think the error is referring to this:

if self._session is not None:
# Request with re-usable session
return self._request_with_session(self.session, *args, **kwargs)
else:
# Request without re-usable session
async with aiohttp.ClientSession() as session:
return self._request_with_session(session, *args, **kwargs)

@adamjmcgrath
Copy link
Contributor

Thanks for raising this @chipxsd

Have identified the issue and a fix is in flight #556

Please continue to use 4.5.0 until this is resolved

@WarpedPixel
Copy link

This also seems to break the _async methods which suddenly return a coroutine instead of the object. For example

response = await self.auth0.users.create_async({'given_name': given_name,
  [...]
})
return response['user_id']  # indexing breaks here in 4.6 because response is a coroutine

returns a coroutine even after the await. This code works unchanged with 4.4 (and returns a dict) but breaks with 4.6 (and returns a coroutine).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This points to a verified bug in the code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants