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

Fix SanicException quiet attribute handling when set to False #3009

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion sanic/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ def __init__(
status_code = status_code or getattr(
self.__class__, "status_code", None
)
quiet = quiet or getattr(self.__class__, "quiet", None)
quiet = (
quiet
if quiet is not None
else getattr(self.__class__, "quiet", None)
)
headers = headers or getattr(self.__class__, "headers", {})
if message is None:
message = self.message
Expand Down
15 changes: 15 additions & 0 deletions tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,21 @@ class CustomError(SanicException):
assert SanicException("").message == ""


def test_exception_quiet_attribute():
class SilentException(SanicException):
quiet = True

class NoisyException(SanicException):
quiet = False

assert SilentException().quiet
assert not NoisyException().quiet
assert SilentException(quiet=True).quiet
assert NoisyException(quiet=True).quiet
assert not SilentException(quiet=False).quiet
assert not NoisyException(quiet=False).quiet


def test_request_middleware_exception_on_404(app: Sanic):
"""See https://github.com/sanic-org/sanic/issues/2950"""
counter = count()
Expand Down
Loading