Closed rmasters closed 4 months ago
@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:
no signature found for builtin <method-wrapper '__call__' of dependency_injector.providers.Singleton object at 0x112a9cac0>
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!
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
``` Traceback (most recent call last): File "/Users/ross/that-depends-testcase/test.py", line 23, inEnvironment