Backtestspydanticrun-20261022-024030#13687

Issue #13687 Merged fix PR #13691 Run 22 Oct 2026 · run-20261022-024030 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 root cause identified in the issue: the raw `validate_by_name` config key being embedded into `arguments`/`arguments-v3` core schemas, bypassing the compatibility mapping done in `core_config()`. The independent tests confirm both make all seven scenarios pass, including the `validate_by_alias=False` variant.

Patch B's approach of reading the value from `core_config(title=None)` is arguably more elegant because it reuses the single source of truth rather than duplicating the mapping logic. Patch A duplicates that logic in a new `effective_validate_by_name` property, with a docstring explaining it mirrors `core_config()`, which carries a small drift risk but is clearly documented.

Where A pulls ahead is tests and scope discipline. The issue explicitly calls out two behaviours: `populate_by_name=True` and the "worse variant" `validate_by_alias=False`. Patch A adds regression tests for both in `test_validate_call.py` (including asserting the alias is correctly rejected under `validate_by_alias=False`), and parametrizes the experimental arguments-schema test across both `arguments` and `arguments-v3` schema types and all three config spellings. Patch B only tests `populate_by_name` on `validate_call` and only the `arguments-v3` schema type, leaving the `validate_by_alias=False` variant and the legacy `arguments` schema path untested. Patch B also includes unrelated churn, rewriting `dict(...)` to `{...}` in three existing tests, which is noise in a bug-fix diff.

Patch A's extension to model and dataclass signature generation is beyond the issue's ask and earns no credit on its own, but it is low-risk, consistent with the fix, and covered by a new test, so it does not count against it.

On balance A is the better fix due to materially stronger test coverage of the behaviours the issue names, with no unrelated churn.

Four judges ruled on this ticket in parallel, and the verdict comes from counting their votes. Each saw the issue and the two patches, labelled A and B in random order (two of them saw ours as A), with issue links and version numbers removed. Where tests could check the fix, they also saw the results of tests a separate agent wrote for the issue, run on both patches. None was told which patch was ours. The reasoning above is one judge's, shown verbatim.

Solve

6m 18s

Wall-clock time in the container

Full test suite

No new failures

1,083 passed · 36 skipped · 1,119 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

75vs 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+71 −4
pydantic/_internal/_config.pyindex 5fcfe38a..837807e0 100644@@ -185,6 +185,22 @@ class ConfigWrapper:                 except KeyError:                     raise AttributeError(f'Config has no attribute {name!r}') from None +    @property+    def effective_validate_by_name(self) -> bool:+        """The effective `validate_by_name` value, accounting for the deprecated `populate_by_name` setting+        and for `validate_by_alias=False` implicitly enabling `validate_by_name`.++        This mirrors the patching done in [`core_config()`][pydantic._internal._config.ConfigWrapper.core_config],+        and should be used instead of the raw `validate_by_name` value when it is embedded in core schemas+        (as values set in schemas take precedence over the core config).+        """+        config = self.config_dict+        if (validate_by_name := config.get('validate_by_name')) is not None:+            return validate_by_name+        if (populate_by_name := config.get('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_dataclasses.pyindex a32bc7ae..acd8665c 100644@@ -2784,6 +2784,18 @@ def test_signature():     )  +@pytest.mark.parametrize(+    'config',+    [{'validate_by_name': True}, {'populate_by_name': True}, {'validate_by_alias': False}],+)+def test_signature_validate_by_name(config) -> None:+    @pydantic.dataclasses.dataclass(config=config)+    class Model:+        a: int = Field(alias='this is invalid')++    assert str(inspect.signature(Model)) == '(a: int) -> None'++ def test_inherited_dataclass_signature():     @pydantic.dataclasses.dataclass     class A:tests/test_experimental_arguments_schema.pyindex 34ebf969..e5e40a4a 100644@@ -186,3 +186,20 @@ 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',+    [{'validate_by_name': True}, {'populate_by_name': True}, {'validate_by_alias': False}],+)+def test_arguments_schema_validate_by_name(schema_type: Literal['arguments', 'arguments-v3'], 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)++    if schema_type == 'arguments':+        assert val.validate_python(ArgsKwargs((), {'a': 1})) == ((), {'a': 1})+    else:+        assert val.validate_python({'a': 1}) == ((1,), {})tests/test_validate_call.pyindex de86f03a..186e4ac8 100644@@ -929,6 +929,28 @@ 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'] for e in exc_info.value.errors()] == ['missing_argument', 'unexpected_keyword_argument']++ 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