@@ -267,7 +267,9 @@ def __init__(
267267 # When populate_by_name is True, allow using the field name as an input key,
268268 # but normalize to the preferred alias to keep keys consistent across sources.
269269 matchable_names = set (alias_names )
270- include_name = settings_cls .model_config .get ('populate_by_name' , False )
270+ include_name = settings_cls .model_config .get ('populate_by_name' , False ) or settings_cls .model_config .get (
271+ 'validate_by_name' , False
272+ )
271273 if include_name :
272274 matchable_names .add (field_name )
273275 init_kwarg_name = init_kwarg_names & matchable_names
@@ -369,7 +371,7 @@ def _extract_field_info(self, field: FieldInfo, field_name: str) -> list[tuple[s
369371 else : # string validation alias
370372 field_info .append ((v_alias , self ._apply_case_sensitive (v_alias ), False ))
371373
372- if not v_alias or self .config .get ('populate_by_name' , False ):
374+ if not v_alias or self .config .get ('populate_by_name' , False ) or self . config . get ( 'validate_by_name' , False ) :
373375 annotation = field .annotation
374376 if typing_objects .is_typealiastype (annotation ) or typing_objects .is_typealiastype (get_origin (annotation )):
375377 annotation = _strip_annotated (annotation .__value__ ) # type: ignore[union-attr]
@@ -489,7 +491,13 @@ def _get_resolved_field_value(self, field: FieldInfo, field_name: str) -> tuple[
489491 A tuple that contains the value, preferred key and a flag to determine whether value is complex.
490492 """
491493 field_value , field_key , value_is_complex = self .get_field_value (field , field_name )
492- if not (value_is_complex or (self .config .get ('populate_by_name' , False ) and (field_key == field_name ))):
494+ if not (
495+ value_is_complex
496+ or (
497+ (self .config .get ('populate_by_name' , False ) or self .config .get ('validate_by_name' , False ))
498+ and (field_key == field_name )
499+ )
500+ ):
493501 field_infos = self ._extract_field_info (field , field_name )
494502 preferred_key , * _ = field_infos [0 ]
495503 return field_value , preferred_key , value_is_complex
0 commit comments