Backtestspydanticrun-20261005-183002#13687

Issue #13687 Merged fix PR #13691 Run 5 Oct 2026 · run-20261005-183002 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 arguments schemas embedded the raw `validate_by_name` config key instead of the effective value.

**Patch A** reads the value from `self._config_wrapper.core_config(title=None)`. This reuses the existing compatibility logic, so it should handle both `populate_by_name=True` and `validate_by_alias=False`. The costs are:
- It builds the full core config one extra time for every arguments schema.
- It relies on a method that may mutate state.
- It passes `None` when the key is unset rather than the previous `False` default. This is probably harmless, since the key gets filtered out.

A's tests are weak. They only cover `populate_by_name`, never the worse `validate_by_alias=False` variant the issue highlights, and the experimental-schema test only checks `arguments-v3`. A also rewrites unrelated `dict(...)` → `{...}` lines in existing tests, which is pure churn.

**Patch B** adds a non-mutating `effective_validate_by_name` property. It mirrors `core_config()`'s precedence:
1. explicit `validate_by_name`
2. then `populate_by_name`
3. then `validate_by_alias is False`

B uses it in both arguments schema builders. It also uses it for model and dataclass signature generation, which is an adjacent consistency fix with low risk. Duplicating the precedence logic carries some risk of the two copies drifting apart, but the docstring explains why the property exists.

B's tests are clearly stronger. They are parametrized over both schema types and both triggering configs (`populate_by_name=True`, `validate_by_alias=False`). They check that the alias is rejected when `validate_by_alias=False`. They also test the precedence case (`populate_by_name=False` with `validate_by_name=True`). All of these would fail before the fix.

Correctness is roughly equal. B wins on test coverage of the issue's stated scenarios and on avoiding unrelated test churn.

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

12,399 passed · 500 skipped · 12,899 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

61vs 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+57 −4
pydantic/_internal/_config.pyindex 5fcfe38a..400ab29f 100644@@ -185,6 +185,23 @@ class ConfigWrapper:                 except KeyError:                     raise AttributeError(f'Config has no attribute {name!r}') from None +    @property+    def effective_validate_by_name(self) -> bool:+        """The `validate_by_name` value, taking into account `populate_by_name` and `validate_by_alias`.++        This mirrors the backwards compatibility patching done in `core_config()`, without mutating the config,+        so that it can be used before the core config is built (e.g. when the value is embedded in a core schema,+        which takes precedence over the core config in pydantic-core).+        """+        config = self.config_dict+        validate_by_name = config.get('validate_by_name')+        if validate_by_name is not None:+            return validate_by_name+        populate_by_name = config.get('populate_by_name')+        if populate_by_name is not None:+            return populate_by_name+        return config.get('validate_by_alias') is False+     def core_config(self, title: str | None) -> core_schema.CoreConfig:         """Create a pydantic-core config. 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..27b30a82 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_arguments_schema_validate_by_name_implicit(schema_type, config) -> 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..728088fa 100644@@ -929,6 +929,31 @@ def test_validate_by_name():     assert foo(a=10, c=1) == 11  +@pytest.mark.parametrize('config', [{'populate_by_name': True}, {'validate_by_alias': False}])+def test_validate_by_name_implicit(config) -> None:+    """`populate_by_name=True` and `validate_by_alias=False` both imply `validate_by_name=True`."""++    @validate_call(config=config)+    def foo(a: Annotated[int, Field(alias='b')]):+        return a++    assert foo(a=1) == 1+    if config.get('validate_by_alias', True):+        assert foo(b=1) == 1+    else:+        with pytest.raises(ValidationError, match='Unexpected keyword argument'):+            foo(b=1)+++def test_populate_by_name_false_explicit_validate_by_name() -> None:+    @validate_call(config={'populate_by_name': False, 'validate_by_name': True})+    def foo(a: Annotated[int, Field(alias='b')]):+        return a++    assert foo(a=1) == 1+    assert foo(b=1) == 1++ 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