Not sure how to reproduce, it only happens occasionally. Our app is still in early phase and does not see real traffic.
AttributeError: partially initialized module 'anyio._backends._asyncio' has no attribute 'Event' (most likely due to a circular import)
File "fastapi_azure_auth/openid_config.py", line 79, in _load_openid_config
openid_response = await client.get(config_url)
File "httpx/_client.py", line 1729, in get
return await self.request(
File "httpx/_client.py", line 1506, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
File "httpx/_client.py", line 1593, in send
response = await self._send_handling_auth(
File "httpx/_client.py", line 1621, in _send_handling_auth
response = await self._send_handling_redirects(
File "httpx/_client.py", line 1658, in _send_handling_redirects
response = await self._send_single_request(request)
File "httpx/_client.py", line 1695, in _send_single_request
response = await transport.handle_async_request(request)
File "httpx/_transports/default.py", line 353, in handle_async_request
resp = await self._pool.handle_async_request(req)
File "httpcore/_async/connection_pool.py", line 216, in handle_async_request
status = RequestStatus(request)
File "httpcore/_async/connection_pool.py", line 19, in __init__
self._connection_acquired = AsyncEvent()
File "httpcore/_synchronization.py", line 29, in __init__
self._event = anyio.Event()
File "anyio/_core/_synchronization.py", line 77, in __new__
return get_asynclib().Event()
AttributeError: partially initialized module 'anyio._backends._asyncio' has no attribute 'checkpoint_if_cancelled' (most likely due to a circular import)
File "fastapi_azure_auth/openid_config.py", line 42, in load_config
await self._load_openid_config()
File "fastapi_azure_auth/openid_config.py", line 91, in _load_openid_config
self._load_keys(jwks_response.json()['keys'])
File "httpx/_client.py", line 1975, in __aexit__
await self._transport.__aexit__(exc_type, exc_value, traceback)
File "httpx/_transports/default.py", line 332, in __aexit__
await self._pool.__aexit__(exc_type, exc_value, traceback)
File "httpcore/_async/connection_pool.py", line 326, in __aexit__
await self.aclose()
File "httpcore/_async/connection_pool.py", line 303, in aclose
async with self._pool_lock:
File "httpcore/_synchronization.py", line 15, in __aenter__
await self._lock.acquire()
File "anyio/_core/_synchronization.py", line 117, in acquire
await checkpoint_if_cancelled()
File "anyio/lowlevel.py", line 42, in checkpoint_if_cancelled
await get_asynclib().checkpoint_if_cancelled()
RuntimeError: Unable to fetch provider information. partially initialized module 'anyio._backends._asyncio' has no attribute 'checkpoint_if_cancelled' (most likely due to a circular import)
File "starlette/exceptions.py", line 93, in __call__
raise exc
File "starlette/exceptions.py", line 82, in __call__
await self.app(scope, receive, sender)
File "fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "starlette/routing.py", line 670, in __call__
await route.handle(scope, receive, send)
File "starlette/routing.py", line 418, in handle
await self.app(scope, receive, send)
File "fastapi/applications.py", line 269, in __call__
await super().__call__(scope, receive, send)
File "starlette/applications.py", line 124, in __call__
await self.middleware_stack(scope, receive, send)
File "starlette/middleware/errors.py", line 184, in __call__
raise exc
File "starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "starlette/exceptions.py", line 93, in __call__
raise exc
File "starlette/exceptions.py", line 82, in __call__
await self.app(scope, receive, sender)
File "fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "starlette/routing.py", line 670, in __call__
await route.handle(scope, receive, send)
File "starlette/routing.py", line 266, in handle
await self.app(scope, receive, send)
File "starlette/routing.py", line 65, in app
response = await func(request)
File "fastapi/routing.py", line 217, in app
solved_result = await solve_dependencies(
File "fastapi/dependencies/utils.py", line 524, in solve_dependencies
solved = await call(**sub_values)
File "fastapi_azure_auth/auth.py", line 151, in __call__
await self.openid_config.load_config()
File "fastapi_azure_auth/openid_config.py", line 55, in load_config
raise RuntimeError(f'Unable to fetch provider information. {error}') from error
class AuthSettings(BaseSettings):
SECRET_KEY: str = Field("secret key", env="SECRET_KEY")
BACKEND_CORS_ORIGINS: list[Union[str, AnyHttpUrl]] = [
"http://localhost:7071",
"http://localhost:8000",
"https://foo.azurewebsites.net",
]
OPENAPI_CLIENT_ID: str = Field(default="", env="OPENAPI_CLIENT_ID")
APP_CLIENT_ID: str = Field(default="", env="APP_CLIENT_ID")
TENANT_ID: str = Field(default="", env="TENANT_ID")
class Config:
env_file = "settings.env"
env_file_encoding = "utf-8"
case_sensitive = True
auth_settings = AuthSettings()
class FastAPISettings(BaseSettings):
debug: bool = Field(default=False, env="DEBUG")
title: str = "Foo"
description: str = (
"..."
)
version: str = "0.0.1"
contact: dict = {
"name": "Foo",
}
swagger_ui_oauth2_redirect_url: str = "/oauth2-redirect"
swagger_ui_init_oauth: dict = {
"usePkceWithAuthorizationCodeGrant": True,
"clientId": auth_settings.OPENAPI_CLIENT_ID,
}
class Config:
env_file = "settings.env"
azure_scheme = SingleTenantAzureAuthorizationCodeBearer(
app_client_id=auth_settings.APP_CLIENT_ID,
tenant_id=auth_settings.TENANT_ID,
scopes={
f"api://{auth_settings.APP_CLIENT_ID}/user_impersonation": "user_impersonation",
},
)