Skip to content

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

Closed

Description

@chipxsd

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

Activity

  1. added
    bugThis points to a verified bug in the code
    on Nov 22, 2023
  2. chipxsd commented on Nov 22, 2023

    @chipxsd
    Author

    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)

  3. adamjmcgrath commented on Nov 22, 2023

    @adamjmcgrath
    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

  4. WarpedPixel commented on Nov 23, 2023

    @WarpedPixel

    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).

  5. added a commit that references this issue on Jan 22, 2026
    7625804
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis points to a verified bug in the code

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions