Backtestspydanticrun-20261027-165153#13687

Issue #13687 Merged fix PR #13691 Run 27 Oct 2026 · run-20261027-165153 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 B = our agent, Patch A = the merged fix.

Both patches fix the root cause the same way in effect: the arguments/arguments-v3 schemas stop embedding the raw `validate_by_name` config key and instead embed the value after the `populate_by_name` and `validate_by_alias=False` compatibility mapping. All eight independent tests, covering both the `populate_by_name` case and the `validate_by_alias=False` variant, fail on base and pass on both patches, so correctness on the issue's scenarios is equal.

Tests separate them. Patch B adds tests for both variants the issue describes (`populate_by_name=True` and `validate_by_alias=False`), parametrized across both `arguments` and `arguments-v3` schema types in the experimental module, plus a `validate_call` test that also checks alias behaviour per config and a negative `populate_by_name=False` test. Patch A only tests `populate_by_name=True`, only for `arguments-v3` in the experimental test, and never exercises the 'worse variant' (`validate_by_alias=False`) that the issue explicitly calls out. A also includes unrelated `dict(...)` to `{...}` churn in three existing tests.

On craft, A has a point in its favour: it reuses `core_config()` as the single source of truth rather than duplicating the mapping logic, whereas B introduces `effective_validate_by_name`, which re-implements the compatibility rules and could drift from `core_config()`. B also widens scope by routing model and dataclass signature generation through the new property. That is a plausible adjacent fix (restoring pre-2.11 signature behaviour under `populate_by_name`) but it is untested and changes behaviour outside the issue's ask, so it earns no credit and carries mild risk.

Weighing in order: correctness is a wash, B's tests are materially stronger and directly cover the second reported failure mode, and the scope/craft trade-offs roughly offset (A's test churn and missing coverage versus B's duplication and untested signature change). B is the better patch.

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

11m 55s

Wall-clock time in the container

Full test suite

No new failures

1,079 passed · 36 skipped · 1,115 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

62vs 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+58 −4
pydantic/_internal/_config.pyindex 5fcfe38a..bc274d96 100644@@ -129,6 +129,22 @@ class ConfigWrapper:         else:             self.config_dict = cast(ConfigDict, config) +    @property+    def effective_validate_by_name(self) -> bool:+        """The `validate_by_name` value, taking into account the `populate_by_name` and `validate_by_alias` settings.++        This mirrors the backwards-compatibility patching done in `core_config()`, and should be used+        whenever the value is read before (or independently of) the core config creation.+        """+        config = self.config_dict+        validate_by_name = config.get('validate_by_name')+        if validate_by_name is None:+            validate_by_name = config.get('populate_by_name')+        if validate_by_name is None:+            # `validate_by_name` is implicitly enabled when `validate_by_alias` is set to `False`:+            validate_by_name = config.get('validate_by_alias') is False+        return validate_by_name+     @classmethod     def for_model(         cls,pydantic/_internal/_dataclasses.pyindex 123a487e..c06c6c53 100644@@ -155,7 +155,7 @@ def complete_dataclass(             # as it is the one synthesized by the stdlib `dataclass` module:             init=original_init,             fields=cls.__pydantic_fields__,  # type: ignore-            validate_by_name=config_wrapper.validate_by_name,+            validate_by_name=config_wrapper.effective_validate_by_name,             extra=config_wrapper.extra,             is_dataclass=True,         ),pydantic/_internal/_generate_schema.pyindex 54a11e09..1feee438 100644@@ -2078,7 +2078,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=self._config_wrapper.effective_validate_by_name,         )      def _arguments_v3_schema(@@ -2146,7 +2146,7 @@ class GenerateSchema:          return core_schema.arguments_v3_schema(             parameters_list,-            validate_by_name=self._config_wrapper.validate_by_name,+            validate_by_name=self._config_wrapper.effective_validate_by_name,         )      def _unsubstituted_typevar_schema(self, typevar: typing.TypeVar) -> core_schema.CoreSchema:pydantic/_internal/_model_construction.pyindex a6566209..d3542ce0 100644@@ -669,7 +669,7 @@ def complete_model_class(             generate_pydantic_signature,             init=cls.__init__,             fields=cls.__pydantic_fields__,-            validate_by_name=config_wrapper.validate_by_name,+            validate_by_name=config_wrapper.effective_validate_by_name,             extra=config_wrapper.extra,         ),     )tests/test_experimental_arguments_schema.pyindex 34ebf969..b6901ad3 100644@@ -186,3 +186,14 @@ def test_multiple_references() -> None:     args, kwargs = val.validate_python({'a': {}, 'b': {}})     assert args == ({}, {})     assert kwargs == {}+++@pytest.mark.parametrize('schema_type', ['arguments', 'arguments-v3'])+@pytest.mark.parametrize('config', [{'populate_by_name': True}, {'validate_by_alias': False}])+def test_implicit_validate_by_name(schema_type: Literal['arguments', 'arguments-v3'], config: Any) -> None:+    def func(a: Annotated[int, Field(alias='b')]) -> None: ...++    arguments_schema = generate_arguments_schema(func=func, schema_type=schema_type, config=config)+    val = SchemaValidator(arguments_schema)++    assert val.validate_python(ArgsKwargs((), {'a': 1})) == ((), {'a': 1})tests/test_validate_call.pyindex de86f03a..60f1de0c 100644@@ -929,6 +929,33 @@ def test_validate_by_name():     assert foo(a=10, c=1) == 11  +@pytest.mark.parametrize('config', [dict(populate_by_name=True), dict(validate_by_alias=False)])+def test_validate_by_name_implicit(config) -> None:+    """https://github.com/pydantic/pydantic/issues/13687: `populate_by_name` and `validate_by_alias=False`+    should (implicitly) enable `validate_by_name`, as for models."""++    @validate_call(config=config)+    def foo(a: Annotated[int, Field(alias='b')]):+        return a++    assert foo(a=10) == 10+    if config.get('validate_by_alias', True):+        assert foo(b=10) == 10+    else:+        with pytest.raises(ValidationError):+            foo(b=10)+++def test_populate_by_name_false() -> None:+    @validate_call(config=dict(populate_by_name=False))+    def foo(a: Annotated[int, Field(alias='b')]):+        return a++    assert foo(b=10) == 10+    with pytest.raises(ValidationError):+        foo(a=10)++ 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