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

Dependency overrides don't work as expected #138

Open
reritom opened this issue Oct 12, 2024 · 1 comment · May be fixed by #77
Open

Dependency overrides don't work as expected #138

reritom opened this issue Oct 12, 2024 · 1 comment · May be fixed by #77

Comments

@reritom
Copy link

reritom commented Oct 12, 2024

When using dependency_provider.dependency_overrides, the override seems to overwrite the function in the dependency, but still passes the new function the resolved dependencies of the old function. I would expect the old functions dependencies to be ignored in the overridden context.

from fast_depends import Depends, dependency_provider, inject

def get_parent_dep():
    return 1

def get_dep(parent_dep=Depends(get_parent_dep)):
    return parent_dep + 1

@inject
def my_func(dep=Depends(get_dep)):
    print(dep + 1)


my_func() # Normal, as expected

dependency_provider.dependency_overrides[get_dep] = lambda: 100

my_func() # Error as my override lambda is being passed a dependency from the old get_dep function
(.venv) $ python test.py 
3
Traceback (most recent call last):
  File "main.py", line 21, in <module>
    my_func()
  File "/.venv/lib/python3.9/site-packages/fast_depends/use.py", line 169, in injected_wrapper
    r = real_model.solve(
  File ".venv/lib/python3.9/site-packages/fast_depends/core/model.py", line 370, in solve
    dep.solve(
  File ".venv/lib/python3.9/site-packages/fast_depends/core/model.py", line 416, in solve
    response = call(*final_args, **final_kwargs)
TypeError: <lambda>() got an unexpected keyword argument 'parent_dep'

Using version 2.4.11

@Lancetnik
Copy link
Owner

Thank you for the reporting! I know about this problem and it fixed already in 3.0.0
Please, wait a bit

@Lancetnik Lancetnik linked a pull request Oct 12, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants