-
Notifications
You must be signed in to change notification settings - Fork 15
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
Singleton providers broken in FastAPI with 1.13.0 #47
Labels
bug
Something isn't working
Comments
@rmasters, thank you, Ross! Fixed in 1.13.1 |
@lesnik512 I am still seeing this for version 1.13.1 and fastapi 0.111.0:
def init_cognito(
region: str,
user_pool_id: str,
app_client_id: str,
) -> Iterator[Cognito]:
"""Initialize the cognito client."""
try:
yield Cognito(region=region, userPoolId=user_pool_id, client_id=app_client_id)
finally:
pass
class CognitoSettings(BaseSettings):
"""Settings for the cognito client."""
region: str
user_pool_id: str
app_client_id: str
def init_settings() -> Iterator[CognitoSettings]:
"""Initialize the settings."""
try:
yield CognitoSettings()
finally:
pass
class CognitoContainer(BaseContainer):
"""Container for the cognito client."""
settings: CognitoSettings = providers.Singleton(init_settings)
cognito: Cognito = providers.Resource(
init_cognito,
region=settings.region,
userPoolId=settings.user_pool_id,
client_id=settings.app_client_id,
)
async def cognito_auth(
bearer_token: HTTPAuthorizationCredentials | None = Depends(HTTPBearer(auto_error=False)),
cognito: Cognito = Depends(CognitoContainer.cognito),
) -> CurrentUser | None:
"""Authenticate the current user with cognito.
Args:
bearer_token (HTTPAuthorizationCredentials): The users bearer token.
cognito (Cognito): The cognito client.
Returns:
CurrentUser | None: The current user if the bearer token exists.
""" |
actually nevermind, looks like an install issue on my end, sorry for the confusion! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Singleton providers appear to be broken when used as FastAPI dependencies in 1.13.0 (working in 1.12.0).
This appears to only affect direct dependencies: when a Singleton is used as a sub-dependency in a non-Singleton provider, I don't get an error.
Test case
Expected
path_singleton
is an instance ofPath
Actual
Resource and Factory work as expected.
Full stacktrace
Environment
The text was updated successfully, but these errors were encountered: