Skip to content
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

Bug: provider overriding does not works with Litestar #119

Closed
nightblure opened this issue Nov 16, 2024 · 2 comments · Fixed by #120
Closed

Bug: provider overriding does not works with Litestar #119

nightblure opened this issue Nov 16, 2024 · 2 comments · Fixed by #120
Labels
bug Something isn't working litestar

Comments

@nightblure
Copy link
Contributor

nightblure commented Nov 16, 2024

Hi!

I discovered that dependency overriding does not work with Litestar. I provide you with two tests with which you can try to reproduce the error:

def test_litestar_di_override_fail_on_provider_override() -> None:
    with TestClient(app=app) as client:
        with DIContainer.int_fn.override_context(12345364758999):
            response = client.get("/router/controller/handler")

    assert response.status_code == HTTP_200_OK, response.text
    assert response.json() == {
        "app_dependency": False,
        "controller_dependency": ["some"],
        "local_dependency": 12345364758999,  # ASSERTION ERROR HERE
        "router_dependency": "",
    }


def test_litestar_di_override_fail_on_override_providers() -> None:
    overrides = {
        'int_fn': 12345364758999,
    }

    with TestClient(app=app) as client:
        with DIContainer.override_providers(overrides):
            response = client.get("/router/controller/handler")

    assert response.status_code == HTTP_200_OK, response.text
    assert response.json() == {
        "app_dependency": False,
        "controller_dependency": ["some"],
        "local_dependency": 12345364758999,  # ASSERTION ERROR HERE
        "router_dependency": "",
    }

I haven’t yet figured out what’s going on: in the overriding logic or the litestar itself


Litestar version: 2.12.1
that-depends version: latest

@lesnik512 lesnik512 linked a pull request Nov 17, 2024 that will close this issue
@lesnik512
Copy link
Member

Hi! Interesting, overriding in fastapi works, Trying to figure out also

@lesnik512
Copy link
Member

Seems like Litestar for some reason clones object, passed to Provide.
Because it has different id inside test client request and outside.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working litestar
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants