-
- Notifications
You must be signed in to change notification settings - Fork 340
Closed
Description
This annoying problem drives me crazy(
Famous "AttributeError: 'Provide' object has no attribute 'read_vacant'"
I tried different types of wiring slicing and dicing the source back and forth, but no clue what's wrong((
Dependency are located in both http_api.py and in tg_bot_clauses.py. The latter is initialized fine (no FastApi), the the first one with FastApi just doesn't want to work.
fastapi==0.79.0
dependency-injector ==4.39.1
src/p2p src/p2p/__init__.py src/p2p/api_main.py src/p2p/bot_main.py src/p2p/py.typed src/p2p/api src/p2p/api/__init__.py src/p2p/api/http_api.py src/p2p/api/tg_bot_clauses.py src/p2p/wiring.py > pipenv run uvicorn src.p2p.api_main:app ... await intent_repo.read_vacant("some") AttributeError: 'Provide' object has no attribute 'read_vacant' # api_main.py from fastapi import FastAPI import p2p.api.http_api as api from .wiring import Container def create_app() -> FastAPI: container = Container() # container.wire(modules=[http_api]) app = FastAPI() app.container = container app.include_router(api.router) return app app = create_app()# wiring.py from typing import cast from dependency_injector import containers, providers from sqlalchemy.ext.asyncio import AsyncEngine, create_async_engine from p2p.api import http_api def get_async_db_engine(dsn: str) -> AsyncEngine: engine = cast( AsyncEngine, create_async_engine(dsn, echo=True, pool_pre_ping=True), ) return engine class Container(containers.DeclarativeContainer): wiring_config = containers.WiringConfiguration(packages=[http_api]) db_engine = providers.Singleton( get_async_db_engine, "mysql+aiomysql://user:pass@host/db" ) intent_repo = providers.Singleton(AlchemyIntentionRepo, db_engine.provided)# http_api.py from dependency_injector.wiring import Provide, inject from fastapi import APIRouter, Depends, status from p2p.wiring import Container router = APIRouter() @router.post("/my-ads", status_code=status.HTTP_201_CREATED) @inject async def post_new_ads( intent_repo: IntentionRepo = Depends(Provide[Container.intent_repo]), ): await intent_repo.read_vacant("some")Metadata
Metadata
Assignees
Labels
No labels