Skip to content

Commit

Permalink
fix: #2368 - before_request handler modifies handler signature (#2391)
Browse files Browse the repository at this point in the history
Signed-off-by: Janek Nouvertné <[email protected]>
  • Loading branch information
provinzkraut authored Sep 30, 2023
1 parent 4ef5fee commit 2d7ad67
Showing 1 changed file with 0 additions and 15 deletions.
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

0 comments on commit 2d7ad67

Please sign in to comment.