Backtestspydanticrun-20261002-175417#13687

Issue #13687 Merged fix PR #13691 Run 2 Oct 2026 · run-20261002-175417 pydantic/pydantic

populate_by_name (and implicit validate_by_name when validate_by_alias=False) is ignored by @validate_call

Better

Our patch was judged better than the merged fix.

In this judgment, Patch A = our agent, Patch B = the merged fix.

Both patches fix the populate_by_name case. Patch A makes `ConfigWrapper.validate_by_alias` and `validate_by_name` return effective values through a shared `_resolve_validate_by_alias_and_name` helper, and `core_config()` reuses that same helper. Every consumer of the config wrapper, including the arguments schemas, now sees consistent values, which addresses the root cause the issue describes. Patch B instead calls `core_config(title=None)` inside each arguments-schema builder. That also yields the patched value for both scenarios, but it rebuilds the full core config as a side computation, can re-trigger any warnings emitted in `core_config`, and leaves `config_wrapper.validate_by_name` inconsistent for other callers. On tests, Patch A covers both scenarios from the issue (`populate_by_name=True` and the worse `validate_by_alias=False` variant) for both the `arguments` and `arguments-v3` schema types and through `validate_call`, including the expected errors. Patch B tests only `populate_by_name`, does not test the `validate_by_alias=False` case, and adds unrelated churn by rewriting `dict(...)` to `{...}` in existing tests. Patch A is more complete, better tested, and cleaner in scope.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

10m 7s

Wall-clock time in the container

Full test suite

No new failures

12,398 passed · 500 skipped · 12,898 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

96vs 39 merged

Changed lines, ours vs merged

Initial Checks

  • I confirm that I'm using Pydantic V2

Description

Since v2.11, @validate_call(config=ConfigDict(populate_by_name=True)) no longer allows passing an aliased parameter by its name — the same config on a BaseModel works, and the 2 docs say it is strictly equivalent to validate_by_name=True, validate_by_alias=True (deprecated in v3, but still supported). Works on 2.10.6; broken on 2.11.x, 2.12.x, and main.

A worse variant: @validate_call(config=ConfigDict(validate_by_alias=False)) makes the aliased parameter impossible to provide at all (both name and alias raise), even though #11503 made validate_by_alias=False implicitly enable validate_by_name.

Root cause: _arguments_schema()/_arguments_v3_schema() embed validate_by_name=self._config_wrapper.validate_by_name into the core schema (_generate_schema.py:2081/2149), reading the raw config key. The backwards-compatibility patch mapping populate_by_name → validate_by_name only runs inside ConfigWrapper.core_config(), and pydantic-core gives the schema-embedded value precedence over the validator config, so the patched core config is never consulted. Models are unaffected because model-fields schemas don't embed the flag.

I have a fix ready and will open a PR.

Example Code

from typing import Annotated
from pydantic import Field, validate_call

@validate_call(config=dict(populate_by_name=True))
def f(a: Annotated[int, Field(alias='b')]) -> int:
    return a

f(b=1)  # OK
f(a=1)  # ValidationError: Unexpected keyword argument

Python, Pydantic & OS Version

             pydantic version: 2.14.0b1
        pydantic-core version: 2.48.0
          pydantic-core build: profile=release pgo=false
               python version: 3.11.14 (main, Oct  9 2025, 16:16:55) [Clang 17.0.0 (clang-1700.4.4.1)]
                     platform: macOS-26.5.2-arm64-arm-64bit
             related packages: typing_extensions-4.16.0
                       commit: 2151025

(also reproduced on released pydantic 2.11.10 and 2.12.5; not reproducible on 2.10.6)

The two patches

Our patch+85 −11
pydantic/_internal/_config.pyindex 5fcfe38a..e28a86ec 100644@@ -177,6 +177,12 @@ class ConfigWrapper:     if not TYPE_CHECKING:  # pragma: no branch          def __getattr__(self, name: str) -> Any:+            if name == 'validate_by_alias' or name == 'validate_by_name':+                # Resolve the effective values, taking `populate_by_name` and the+                # implicit `validate_by_name` (when `validate_by_alias=False`) into account:+                validate_by_alias, validate_by_name = _resolve_validate_by_alias_and_name(self.config_dict)+                value = validate_by_alias if name == 'validate_by_alias' else validate_by_name+                return config_defaults[name] if value is None else value             try:                 return self.config_dict[name]             except KeyError:@@ -209,17 +215,11 @@ class ConfigWrapper:                 stacklevel=2,             ) -        if (populate_by_name := config.get('populate_by_name')) is not None:-            # We include this patch for backwards compatibility purposes, but this config setting will be deprecated in v3.0, and likely removed in v4.0.-            # Thus, the above warning and this patch can be removed then as well.-            if config.get('validate_by_name') is None:-                config['validate_by_alias'] = True-                config['validate_by_name'] = populate_by_name--        # We dynamically patch validate_by_name to be True if validate_by_alias is set to False-        # and validate_by_name is not explicitly set.-        if config.get('validate_by_alias') is False and config.get('validate_by_name') is None:-            config['validate_by_name'] = True+        validate_by_alias, validate_by_name = _resolve_validate_by_alias_and_name(config)+        if validate_by_alias is not None:+            config['validate_by_alias'] = validate_by_alias+        if validate_by_name is not None:+            config['validate_by_name'] = validate_by_name          if (not config.get('validate_by_alias', True)) and (not config.get('validate_by_name', False)):             raise PydanticUserError(@@ -342,6 +342,25 @@ def prepare_config(config: ConfigDict | dict[str, Any] | type[Any] | None) -> Co     return config_dict  +def _resolve_validate_by_alias_and_name(config: ConfigDict) -> tuple[bool | None, bool | None]:+    """Resolve the effective `validate_by_alias` and `validate_by_name` values of a config.++    `None` is returned for a value that is neither set explicitly nor implied by other settings.+    """+    validate_by_alias = config.get('validate_by_alias')+    validate_by_name = config.get('validate_by_name')+    if validate_by_name is None:+        if (populate_by_name := config.get('populate_by_name')) is not None:+            # We include this patch for backwards compatibility purposes, but this config setting will be+            # deprecated in v3.0, and likely removed in v4.0. Thus, this patch can be removed then as well.+            return True, populate_by_name+        if validate_by_alias is False:+            # `validate_by_name` is implicitly enabled if `validate_by_alias` is set to `False`+            # and `validate_by_name` is not explicitly set.+            return validate_by_alias, True+    return validate_by_alias, validate_by_name++ config_keys = set(ConfigDict.__annotations__.keys())  tests/test_experimental_arguments_schema.pyindex 34ebf969..27d42ccf 100644@@ -66,6 +66,35 @@ def test_arguments_v3() -> None:     assert kwargs == {'c': 5}  +@pytest.mark.parametrize('schema_type', ['arguments', 'arguments-v3'])+def test_arguments_populate_by_name(schema_type: Literal['arguments', 'arguments-v3']) -> None:+    def func(a: Annotated[int, Field(alias='b')]) -> None: ...++    arguments_schema = generate_arguments_schema(+        func=func,+        schema_type=schema_type,+        config={'populate_by_name': True},+    )+    val = SchemaValidator(arguments_schema)++    assert val.validate_python(ArgsKwargs((), {'a': 1})) == ((), {'a': 1})+    assert val.validate_python(ArgsKwargs((), {'b': 1})) == ((), {'a': 1})+++@pytest.mark.parametrize('schema_type', ['arguments', 'arguments-v3'])+def test_arguments_validate_by_alias_false(schema_type: Literal['arguments', 'arguments-v3']) -> None:+    def func(a: Annotated[int, Field(alias='b')]) -> None: ...++    arguments_schema = generate_arguments_schema(+        func=func,+        schema_type=schema_type,+        config={'validate_by_alias': False},+    )+    val = SchemaValidator(arguments_schema)++    assert val.validate_python(ArgsKwargs((), {'a': 1})) == ((), {'a': 1})++ def test_arguments_v3_alias_generator() -> None:     def func(*, a: int) -> None: ... tests/test_validate_call.pyindex de86f03a..d2fbae26 100644@@ -929,6 +929,32 @@ def test_validate_by_name():     assert foo(a=10, c=1) == 11  +def test_populate_by_name():+    @validate_call(config=dict(populate_by_name=True))+    def foo(a: Annotated[int, Field(alias='b')], c: Annotated[int, Field(alias='d')]):+        return a + c++    assert foo(b=10, d=1) == 11+    assert foo(a=10, d=1) == 11+    assert foo(b=10, c=1) == 11+    assert foo(a=10, c=1) == 11+++def test_validate_by_alias_false_implies_validate_by_name():+    @validate_call(config=dict(validate_by_alias=False))+    def foo(a: Annotated[int, Field(alias='b')]):+        return a++    assert foo(a=10) == 10++    with pytest.raises(ValidationError) as exc_info:+        foo(b=10)+    assert [(e['type'], e['loc']) for e in exc_info.value.errors()] == [+        ('missing_argument', ('a',)),+        ('unexpected_keyword_argument', ('b',)),+    ]++ def test_validate_return():     @validate_call(config=dict(validate_return=True))     def foo(a: int, b: int) -> int: 
Merged fix · PR #13691+34 −5
pydantic/_internal/_generate_schema.pyindex 54a11e09f..37c761f40 100644@@ -2025,6 +2025,8 @@ class GenerateSchema:         var_kwargs_schema: core_schema.CoreSchema | None = None         var_kwargs_mode: core_schema.VarKwargsMode | None = None +        core_config = self._config_wrapper.core_config(title=None)+         for i, (name, p) in enumerate(sig.parameters.items()):             if p.annotation is sig.empty:                 annotation = typing.cast(Any, Any)@@ -2078,7 +2080,7 @@ class GenerateSchema:             var_args_schema=var_args_schema,             var_kwargs_mode=var_kwargs_mode,             var_kwargs_schema=var_kwargs_schema,-            validate_by_name=self._config_wrapper.validate_by_name,+            validate_by_name=core_config.get('validate_by_name'),         )      def _arguments_v3_schema(@@ -2098,6 +2100,7 @@ class GenerateSchema:         type_hints = _typing_extra.get_function_type_hints(function, globalns=globalns, localns=localns)          parameters_list: list[core_schema.ArgumentsV3Parameter] = []+        core_config = self._config_wrapper.core_config(title=None)          for i, (name, p) in enumerate(sig.parameters.items()):             if parameters_callback is not None:@@ -2146,7 +2149,7 @@ class GenerateSchema:          return core_schema.arguments_v3_schema(             parameters_list,-            validate_by_name=self._config_wrapper.validate_by_name,+            validate_by_name=core_config.get('validate_by_name'),         )      def _unsubstituted_typevar_schema(self, typevar: typing.TypeVar) -> core_schema.CoreSchema:tests/test_experimental_arguments_schema.pyindex 34ebf9692..0863bd4b5 100644@@ -186,3 +186,19 @@ def test_multiple_references() -> None:     args, kwargs = val.validate_python({'a': {}, 'b': {}})     assert args == ({}, {})     assert kwargs == {}+++def test_populate_by_name() -> None:+    """https://github.com/pydantic/pydantic/issues/13687"""++    def func(a: Annotated[int, Field(alias='b')]) -> None: ...++    arguments_schema = generate_arguments_schema(+        func=func,+        schema_type='arguments-v3',+        config={'populate_by_name': True},+    )+    val = SchemaValidator(arguments_schema)+    args, kwargs = val.validate_python({'a': 1})+    assert args == (1,)+    assert kwargs == {}tests/test_validate_call.pyindex de86f03a9..3d86e4517 100644@@ -919,7 +919,7 @@ def test_use_of_alias():   def test_validate_by_name():-    @validate_call(config=dict(validate_by_name=True))+    @validate_call(config={'validate_by_name': True})     def foo(a: Annotated[int, Field(alias='b')], c: Annotated[int, Field(alias='d')]):         return a + c @@ -929,8 +929,18 @@ def test_validate_by_name():     assert foo(a=10, c=1) == 11  +def test_populate_by_name() -> None:+    """https://github.com/pydantic/pydantic/issues/13687"""++    @validate_call(config={'populate_by_name': True})+    def foo(a: Annotated[int, Field(alias='b')]):+        return a++    assert foo(a=1) == 1++ def test_validate_return():-    @validate_call(config=dict(validate_return=True))+    @validate_call(config={'validate_return': True})     def foo(a: int, b: int) -> int:         return a + b @@ -938,7 +948,7 @@ def test_validate_return():   def test_validate_all():-    @validate_call(config=dict(validate_default=True))+    @validate_call(config={'validate_default': True})     def foo(dt: datetime = Field(default_factory=lambda: 946684800)):         return dt