Skip to content

AsyncManagementClient with custom_domain fails every request with TypeError #906

Open

Description

@RaphaelFakhri

Description

When you create AsyncManagementClient with custom_domain, every request raises:

TypeError: object NoneType can't be used in 'await' expression

AsyncManagementClient.__init__ adds _enforce_custom_domain_whitelist to the request event hooks of an httpx.AsyncClient. That function is synchronous. httpx.AsyncClient awaits each request hook (await hook(request)), so awaiting the None it returns raises TypeError before the request is sent. The sync ManagementClient is not affected.

Reproduction

import asyncio
import httpx
from auth0.management import AsyncManagementClient

async def main():
    client = AsyncManagementClient(
        domain="tenant.auth0.com",
        token="TOKEN",
        custom_domain="login.example.com",
        httpx_client=httpx.AsyncClient(
            transport=httpx.MockTransport(lambda r: httpx.Response(200, json={}))
        ),
    )
    await client.users.get("auth0|abc123")

asyncio.run(main())

The same error occurs without httpx_client, since the SDK then creates its own httpx.AsyncClient and adds the same hook.

Additional context

Expected: the request is sent, with the Auth0-Custom-Domain header kept on whitelisted paths and removed on other paths, as with ManagementClient.

httpx 0.28.1. Custom domain support was added in #799.

auth0-python version

6.8.0

Python version

3.12

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions