From 5df293ac72f983536612369704316f2ddc61e68b Mon Sep 17 00:00:00 2001 From: Tiago Silva Date: Sun, 10 Nov 2024 22:14:18 +0100 Subject: [PATCH] Fix taskfile for simple projects (#430) * Reorganise some code and clear unused vars * Fix taskfile --- .../project_template_simple/Taskfile.yaml.e-tpl | 2 -- esmerald/routing/_internal.py | 12 ++++++------ esmerald/routing/base.py | 1 - esmerald/transformers/model.py | 1 - 4 files changed, 6 insertions(+), 10 deletions(-) diff --git a/esmerald/conf/directives/project_template_simple/Taskfile.yaml.e-tpl b/esmerald/conf/directives/project_template_simple/Taskfile.yaml.e-tpl index be9777d5..134687bb 100644 --- a/esmerald/conf/directives/project_template_simple/Taskfile.yaml.e-tpl +++ b/esmerald/conf/directives/project_template_simple/Taskfile.yaml.e-tpl @@ -9,8 +9,6 @@ tasks: run: desc: Starts {{ project_name }} in development mode - env: - ESMERALD_SETTINGS_MODULE: {{ project_name }}.configs.development.settings.DevelopmentAppSettings cmds: - esmerald runserver diff --git a/esmerald/routing/_internal.py b/esmerald/routing/_internal.py index acbd2e06..a272c5e1 100644 --- a/esmerald/routing/_internal.py +++ b/esmerald/routing/_internal.py @@ -21,7 +21,7 @@ def get_base_annotations(base_annotation: Any) -> Dict[str, Any]: Returns the annotations of the base class. Args: - base (Any): The base class. + base_annotation (Any): The base class. Returns: Dict[str, Any]: The annotations of the base class. @@ -195,17 +195,17 @@ def get_data_field(handler: Union["HTTPHandler", "WebhookHandler", Any]) -> Any: default to the normal Esmerald processing, otherwise it will use the complex approach of designing the OpenAPI body. """ + # If there are no body fields, we simply return the original + # default Esmerald body parsing + if not handler.body_encoder_fields: + return get_original_data_field(handler) + is_data_or_payload = ( DATA if DATA in handler.signature_model.model_fields else (PAYLOAD if PAYLOAD in handler.signature_model.model_fields else None) ) - # If there are no body fields, we simply return the original - # default Esmerald body parsing - if not handler.body_encoder_fields: - return get_original_data_field(handler) - if len(handler.body_encoder_fields) < 2 and is_data_or_payload is not None: return get_original_data_field(handler) return get_complex_data_field(handler, fields=handler.body_encoder_fields) diff --git a/esmerald/routing/base.py b/esmerald/routing/base.py index b2d882a8..3b6676ae 100644 --- a/esmerald/routing/base.py +++ b/esmerald/routing/base.py @@ -166,7 +166,6 @@ async def _get_response_data( Any: The response data generated by processing the request. """ signature_model = get_signature(route) - is_data_or_payload: str = None if parameter_model.has_kwargs: kwargs: Dict[str, Any] = parameter_model.to_kwargs(connection=request, handler=route) diff --git a/esmerald/transformers/model.py b/esmerald/transformers/model.py index b4c268c8..24ef16c4 100644 --- a/esmerald/transformers/model.py +++ b/esmerald/transformers/model.py @@ -25,7 +25,6 @@ from esmerald.types import Dependencies # pragma: no cover from esmerald.websockets import WebSocket # pragma: no cover - MEDIA_TYPES = [EncodingType.MULTI_PART, EncodingType.URL_ENCODED] MappingUnion = Mapping[Union[int, str], Any]