Skip to content

Commit b6ea9d9

Browse files
committed
Fix for init source kwarg alias resolution.
1 parent f76c7fe commit b6ea9d9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

pydantic_settings/sources.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,15 @@ def __init__(
388388
init_kwargs: dict[str, Any],
389389
nested_model_default_partial_update: bool | None = None,
390390
):
391-
self.init_kwargs = init_kwargs
391+
self.init_kwargs = {}
392+
init_kwargs_names = set(init_kwargs.keys())
393+
for field_name, field_info in settings_cls.model_fields.items():
394+
alias_names, *_ = _get_alias_names(field_name, field_info)
395+
init_kwarg_name = init_kwargs_names & set(alias_names)
396+
if init_kwarg_name:
397+
preferred_alias = alias_names[0]
398+
self.init_kwargs[preferred_alias] = init_kwargs[init_kwarg_name.pop()]
399+
392400
super().__init__(settings_cls)
393401
self.nested_model_default_partial_update = (
394402
nested_model_default_partial_update

0 commit comments

Comments
 (0)