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: #2368 - before_request handler modifies handler signature #2391

Merged
merged 4 commits into from
Sep 30, 2023
Merged
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
15 changes: 0 additions & 15 deletions litestar/handlers/http_handlers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,6 @@ def get_response_handler(self, is_response_type_data: bool = False) -> Callable[
return_type = self.parsed_fn_signature.return_type
return_annotation = return_type.annotation

if before_request_handler := self.resolve_before_request():
handler_return_type = before_request_handler.parsed_signature.return_type
if not handler_return_type.is_subclass_of((Empty, NoneType)):
return_annotation = handler_return_type.annotation

self._response_handler_mapping["response_type_handler"] = response_type_handler = create_response_handler(
after_request=after_request,
background=self.background,
Expand Down Expand Up @@ -494,9 +489,6 @@ async def to_response(self, app: Litestar, data: Any, request: Request) -> ASGIA
return await response_handler(app=app, data=data, request=request) # type: ignore

def on_registration(self, app: Litestar) -> None:
if before_request := self.resolve_before_request():
before_request.set_parsed_signature(self.resolve_signature_namespace())

super().on_registration(app)
self.resolve_after_response()
self.resolve_include_in_schema()
Expand Down Expand Up @@ -527,13 +519,6 @@ def _validate_handler_function(self) -> None:
"If the function should return a value, change the route handler status code to an appropriate value.",
)

if (
(before_request := self.resolve_before_request())
and not before_request.parsed_signature.return_type.is_subclass_of(NoneType)
and not before_request.parsed_signature.return_type.is_optional
):
return_type = before_request.parsed_signature.return_type

if not self.media_type:
if return_type.is_subclass_of((str, bytes)) or return_type.annotation is AnyStr:
self.media_type = MediaType.TEXT
Expand Down