Closed pythrick closed 1 year ago
It's a pretty strange cuz Propan as a FastAPI router uses a FastAPI DI system. Anyway, will check and fix it tomorrow, thanks for the Issue.
@pythrick the job is done! Just update Propan to 0.1.5.13
and FastAPI yield Depends works fine.
@Lancetnik thank you for the quick fix! It was fast! I'm really enjoying this framework, thank you for your great work building it.
@Lancetnik thank you for the quick fix! It was fast! I'm really enjoying this framework, thank you for your great work building it.
Thank you for the Issue and for the FastDepends contribution too! I am always trying to fix any bugs issues in the same day (or a few days later), so be free to report of any bugs or features you wish to see in the Propan.
Also, if you are so enjoied by Propan, please tell others about it (by tweet, article, smth). The bigger community we have - the better project will be!
Description When trying to use a FastAPI dependency function with a yield statement in Propan, I found that the function is not awaited. The assert error is raised in this case, but using a function with a return statement instead of yield works fine.
Steps to reproduce
Define a FastAPI dependency function with a
yield
statement:Use it as a dependency in a Propan event function:
Run the app and make a
GET
request. An AssertionError is raised.Expected behavior The dependency function
get_db
should be awaited, just as when we use FastAPI's dependency injection system for HTTP requests.Actual behavior The AssertionError is raised when trying to use a dependency function with a
yield
.Environment:
Additional information
I believe the issue happens because in Propan, the cleanup part of a dependency function that yields (the part that comes after the
yield
statement) never gets run. FastAPI's dependencies are designed with HTTP request lifespans in mind, and as such dependency functions usingyield
are treated as context managers that perform cleanup after each request. The issue could be due to Propan not fully supporting this model, especially when it comes to context manager behavior of dependencies.Any assistance would be greatly appreciated!