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
fix: avoid conversion to bool in debug response #2384
Conversation
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.
I suggest adding a test - this is the type of thing that a tool, or an overzealous refactor might reverse at some point down the track without realizing why it is why it is.
This reproduces it:
from inspect import getinnerframes
from litestar.middleware.exceptions._debug_response import get_symbol_name
def test_get_symbol_name_where_type_doesnt_support_bool() -> None:
class Test:
def __bool__(self) -> bool:
raise TypeError("This type doesn't support bool")
def method(self) -> None:
raise RuntimeError("Oh no!")
try:
Test().method()
except Exception as e:
exc = e
frame = getinnerframes(exc.__traceback__, 2)[-1]
assert get_symbol_name(frame) == "Test.method"
4f39cad
to
f4b3348
Compare
I've added the test. I added some type guards because pyright complained about |
f4b3348
to
965d2d5
Compare
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.
Thanks for this!
Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/2384 |
@all-contributors add @geeshta for code bug |
I've put up a pull request to add @geeshta! 🎉 |
Pull Request Checklist
Description
Avoid implicit conversion to
bool
in_debug_response.py
as this causes problems with some sqlalchemy classes, where instead of the original DB error being propagated, aTypeError
is raised. See #2381Close Issue(s)
Closes #2381