-
-
Notifications
You must be signed in to change notification settings - Fork 8k
✨ Let solve_dependencies
re-raise the RuntimeError
when a generator didn't yield anything
#13264
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
base: master
Are you sure you want to change the base?
Conversation
📝 Docs preview for commit 9d6d765 at: https://bdb75a41.fastapitiangolo.pages.dev Modified Pages |
This resolves #13238, by making the raised exception more informative, and by adding an example of a badly-behaving async dependency to the docs. |
9d6d765
to
99426b4
Compare
If an async generator dependency raises RuntimeError: generator didn't yield, make solve_dependencies catch and re-raise it, to more easily identify the dependency responsible for the error, and to provide more information on how to fix the dependency
99426b4
to
efe0e06
Compare
📝 Docs preview for commit efe0e06 at: https://113b4278.fastapitiangolo.pages.dev Modified Pages |
solve_dependencies
re-raise the RuntimeError
when a generator didn't yield anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Jaza, thanks for your interest!
I think adding a clear error message is a good idea.
As for updating docs - I think we don't need these code examples. Everything should be clear in current version.
We can just add tests for sync
and async
dependencies to make sure it works
try: | ||
solved = await stack.enter_async_context(cm) | ||
except RuntimeError as ex: | ||
if "generator didn't yield" not in f"{ex}": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if "generator didn't yield" not in f"{ex}": | |
if str(ex) == "generator didn't yield": |
This should be faster
"this is a dependency with yield that has a block with a bare except, or a " | ||
"block with except Exception, and is not raising the exception again. Read " | ||
"more about it in the docs: " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"this is a dependency with yield that has a block with a bare except, or a " | |
"block with except Exception, and is not raising the exception again. Read " | |
"more about it in the docs: " | |
"this is a dependency with yield that catches an exception using except, " | |
"but doesn't raise the exception again. Read more about it in the docs: " |
If an async generator dependency raises
RuntimeError: generator didn't yield
, makesolve_dependencies
catch and re-raise it, to more easily identify the dependency responsible for the error, and to provide more information on how to fix the dependency.