77from typing import TYPE_CHECKING , Any , Callable , Mapping , MutableMapping , Sequence
88from urllib .parse import parse_qs
99
10- from pydantic import BaseModel , ValidationError
10+ from pydantic import BaseModel
1111
1212from aws_lambda_powertools .event_handler .middlewares import BaseMiddlewareHandler
1313from aws_lambda_powertools .event_handler .openapi .compat import (
@@ -69,8 +69,8 @@ def handler(self, app: EventHandlerInstance, next_middleware: NextMiddleware) ->
6969 route .dependant .query_params ,
7070 )
7171
72- # Process query values (with Pydantic model support)
73- query_values , query_errors = _request_params_to_args_with_pydantic_support (
72+ # Process query values
73+ query_values , query_errors = _request_params_to_args (
7474 route .dependant .query_params ,
7575 query_string ,
7676 )
@@ -81,8 +81,8 @@ def handler(self, app: EventHandlerInstance, next_middleware: NextMiddleware) ->
8181 route .dependant .header_params ,
8282 )
8383
84- # Process header values (with Pydantic model support)
85- header_values , header_errors = _request_params_to_args_with_pydantic_support (
84+ # Process header values
85+ header_values , header_errors = _request_params_to_args (
8686 route .dependant .header_params ,
8787 headers ,
8888 )
@@ -311,7 +311,7 @@ def _prepare_response_content(
311311 return res # pragma: no cover
312312
313313
314- def _request_params_to_args_with_pydantic_support (
314+ def _request_params_to_args (
315315 required_params : Sequence [ModelField ],
316316 received_params : Mapping [str , Any ],
317317) -> tuple [dict [str , Any ], list [Any ]]:
@@ -330,71 +330,24 @@ def _request_params_to_args_with_pydantic_support(
330330 from aws_lambda_powertools .event_handler .openapi .compat import lenient_issubclass
331331
332332 if isinstance (field_info , (Query , Header )) and lenient_issubclass (field_info .annotation , BaseModel ):
333- # Handle Pydantic model - use the same approach as _request_body_to_args
334- loc = (field_info .in_ .value , field .alias )
335-
336- # Get the raw data for the Pydantic model
337- value = received_params .get (field .alias )
338-
339- if value is None :
340- if field .required :
341- errors .append (get_missing_field_error (loc ))
342- else :
343- values [field .name ] = deepcopy (field .default )
344- continue
345-
333+ pass
334+ elif isinstance (field_info , Param ):
335+ pass
346336 else :
347- # Regular parameter processing (existing logic)
348- if not isinstance (field_info , Param ):
349- raise AssertionError (f"Expected Param field_info, got { field_info } " )
350-
351- value = received_params .get (field .alias )
352- loc = (field_info .in_ .value , field .alias )
353-
354- if value is None :
355- if field .required :
356- errors .append (get_missing_field_error (loc = loc ))
357- else :
358- values [field .name ] = deepcopy (field .default )
359- continue
360-
361- # Use _validate_field like _request_body_to_args does
362- values [field .name ] = _validate_field (field = field , value = value , loc = loc , existing_errors = errors )
363- return values , errors
364-
365-
366- def _request_params_to_args (
367- required_params : Sequence [ModelField ],
368- received_params : Mapping [str , Any ],
369- ) -> tuple [dict [str , Any ], list [Any ]]:
370- """
371- Convert the request params to a dictionary of values using validation, and returns a list of errors.
372- """
373- values = {}
374- errors = []
375-
376- for field in required_params :
377- field_info = field .field_info
378-
379- # To ensure early failure, we check if it's not an instance of Param.
380- if not isinstance (field_info , Param ):
381337 raise AssertionError (f"Expected Param field_info, got { field_info } " )
382338
383339 value = received_params .get (field .alias )
384-
385340 loc = (field_info .in_ .value , field .alias )
386341
387- # If we don't have a value, see if it's required or has a default
388342 if value is None :
389343 if field .required :
390344 errors .append (get_missing_field_error (loc = loc ))
391345 else :
392346 values [field .name ] = deepcopy (field .default )
393347 continue
394348
395- # Finally, validate the value
349+ # Use _validate_field like _request_body_to_args does
396350 values [field .name ] = _validate_field (field = field , value = value , loc = loc , existing_errors = errors )
397-
398351 return values , errors
399352
400353
@@ -529,7 +482,13 @@ def _normalize_multi_query_string_with_param(
529482 try :
530483 model_data [field_alias ] = query_string [field_alias ][0 ]
531484 except KeyError :
532- pass
485+ if model_class .model_config .get ("validate_by_name" ) or model_class .model_config .get (
486+ "populate_by_name" ,
487+ ):
488+ try :
489+ model_data [field_alias ] = query_string [field_name ][0 ]
490+ except KeyError :
491+ pass
533492
534493 # Store the collected data under the param alias
535494 resolved_query_string [param .alias ] = model_data
0 commit comments