Skip to content

Conversation

@lucasfrancaid
Copy link

When working with dependency_provider.override I had problems when trying to override a dependency function. During debugging, I noticed that dependency_provider was creating a new dependency with override instead of override the original function, see the image below:
image

After getting deeper into the library code, I realised that when a dependency was created, the function name (used as key) was unwrapped so as not to register the @inject instead of the dependency function. See the image below to understand the injection structure:
image

This pull request adds an unwrapping handler to the Provider.__get_original_key method to ensure that the key is treated in the same way as build_call_model does.

@Lancetnik
Copy link
Owner

Lancetnik commented Oct 26, 2025

@lucasfrancaid thank you for the report, but I am not sure, that you are using FastDepends correctly. You shouldn't wrap a function to @inject to use it as a dependency

Please, read #179 (comment)

@lucasfrancaid
Copy link
Author

lucasfrancaid commented Oct 26, 2025

@Lancetnik, got it. But n the real scenario, I need to wrap the function with @inject because sometimes I need to call it directly from the code as a normal function. Even though I can work around this by creating another wrapped function to get just what I need, it starts to feel a bit messy.

The problem I faced was solved by using dependency_provider.override(get_service, unwrap(get_service_mock), and I opened the PR to handle this case, as it is not a big problem and can be used in different ways.

Anyway, if it does not make any sense, sorry for waste your time.

@Lancetnik
Copy link
Owner

@lucasfrancaid np, I'll review and merge the PR. Just wanted to know about your case

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 this pull request may close these issues.

2 participants