From 458e8f144379423cd840728faf1e057d04702b38 Mon Sep 17 00:00:00 2001 From: Pastukhov Nikita Date: Fri, 22 Dec 2023 17:54:40 +0300 Subject: [PATCH] fix: correct yield overriding (#50) --- fast_depends/__about__.py | 2 +- fast_depends/core/model.py | 4 ++-- tests/test_overrides.py | 17 +++++++++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fast_depends/__about__.py b/fast_depends/__about__.py index 3e5cdab..4a3e1be 100644 --- a/fast_depends/__about__.py +++ b/fast_depends/__about__.py @@ -1,3 +1,3 @@ """FastDepends - extracted and cleared from HTTP domain FastAPI Dependency Injection System""" -__version__ = "2.2.6" +__version__ = "2.2.7" diff --git a/fast_depends/core/model.py b/fast_depends/core/model.py index 724e92c..55cdddb 100644 --- a/fast_depends/core/model.py +++ b/fast_depends/core/model.py @@ -332,7 +332,7 @@ def solve( if self.is_generator and nested: response = solve_generator_sync( *final_args, - call=self.call, + call=call, stack=stack, **final_kwargs, ) @@ -418,7 +418,7 @@ async def asolve( if self.is_generator and nested: response = await solve_generator_async( *final_args, - call=self.call, + call=call, stack=stack, **final_kwargs, ) diff --git a/tests/test_overrides.py b/tests/test_overrides.py index da3f899..7abdbd7 100644 --- a/tests/test_overrides.py +++ b/tests/test_overrides.py @@ -67,6 +67,23 @@ def func(d=Depends(base_dep)): assert func() == 1 +def test_override_context_with_yield(provider): + def base_dep(): + yield 1 + + def override_dep(): + yield 2 + + @inject + def func(d=Depends(base_dep)): + return d + + with provider.scope(base_dep, override_dep): + assert func() == 2 + + assert func() == 1 + + def test_sync_by_async_override(provider): def base_dep(): # pragma: no cover return 1