python-dependency-injector icon indicating copy to clipboard operation
python-dependency-injector copied to clipboard

Yet another "Provide object has no attribute ..."

Open elarrat opened this issue 2 years ago • 3 comments

I'm making some initial tests and I'd like to wire my service to my controller. Could anyone please tell me what am I missing?

This is my controller: image

This is my container: image

This is my project structure: image

I'm taking the fastapi example from the docs as a reference. I can't get past this:

File "(...)app\server\controllers\StudentController.py", line 17, in add_student_data
new_student = service.create(body)
AttributeError: 'Provide' object has no attribute 'create'

The whole project can be checked here: https://github.com/elarrat/fastapi-test

I'm kinda stuck in this for days now, so If anyone could take some time to help me I'd very much appreciate it.

elarrat avatar May 09 '22 00:05 elarrat

in controller, @inject decorator should be the closest to the injected function. i guess.

jidan2333 avatar May 17 '22 01:05 jidan2333

Thanks for answering! I did that already, but still a no go. I'm suspecting of the package path in the wiring configurations. It's hard to tell since it doesn't throw any error

elarrat avatar May 26 '22 13:05 elarrat

same here!

dnp1 avatar Jun 30 '22 14:06 dnp1

I was getting this error when running my tests and turns out I had a problem in my app fixture:

Incorrect:

@pytest.fixture
def app():
    """App fixture."""
    flask_app = create_app()
    flask_app.container.unwire()
    return flask_app

Correct:

@pytest.fixture
def app():
    """App fixture."""
    flask_app = create_app()
    yield flask_app
    flask_app.container.unwire()

santalvarez avatar Dec 17 '22 19:12 santalvarez