Backtestspydanticrun-20260930-144322#13687

Issue #13687 Merged fix PR #13691 Run 30 Sep 2026 · run-20260930-144322 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 issue identifies: the raw `self._config_wrapper.validate_by_name` value was embedded into the arguments and arguments-v3 schemas. Patch A replaces it with `core_config(title=None).get('validate_by_name')`, which reuses the existing backwards-compatibility mapping. That is the more elegant single source of truth, but it builds a full core config just to read one key. Patch B adds `_effective_validate_by_name` to `ConfigWrapper`. This property duplicates the precedence rules from `core_config()`: explicit `validate_by_name`, then `populate_by_name`, then `validate_by_alias is False`. It covers both scenarios in the issue, at the cost of a small risk of the two copies drifting apart later. On correctness they are roughly equal, since both handle `populate_by_name=True` and the implicit `validate_by_alias=False` case.

Tests are the deciding factor. Patch B tests the main `populate_by_name` scenario thoroughly: every combination of name and alias for two parameters. It also tests the 'worse variant' the issue highlights, `validate_by_alias=False`, checking that the name works and the alias is rejected. It adds an arguments-v3 test that checks both alias and name input. Patch A tests only `populate_by_name` with a single `foo(a=1)` call, never tests the `validate_by_alias=False` case, and leaves `<link>` placeholder docstrings.

Patch A also adds unrelated churn by rewriting `dict(...)` to `{...}` in existing tests. That is not harmful but obscures the diff. Overall, Patch B's coverage of both reported scenarios outweighs Patch A's slightly cleaner reuse of `core_config()`.

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

3m 30s11 turns

Wall-clock time in the container

Full test suite

No new failures

12,395 passed · 500 skipped · 12,895 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

52vs 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+50 −2
pydantic/_internal/_config.pyindex 5fcfe38a..a471909d 100644@@ -185,6 +185,19 @@ 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, taking `populate_by_name` and `validate_by_alias` into account.++        Mirrors the backwards-compatibility logic applied in `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/_generate_schema.pyindex 54a11e09..5c528213 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:tests/test_experimental_arguments_schema.pyindex 34ebf969..2408db56 100644@@ -84,6 +84,19 @@ def test_arguments_v3_alias_generator() -> None:     assert kwargs == {'a': 1}  +def test_arguments_v3_populate_by_name() -> None:+    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)+    _, kwargs = val.validate_python({'b': 1})+    assert kwargs == {'a': 1}+    _, kwargs = val.validate_python({'a': 1})+    assert kwargs == {'a': 1}++ def test_arguments_v3_kwargs_uniform() -> None:     def func(**kwargs: int) -> None: ... tests/test_validate_call.pyindex de86f03a..40118a23 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():+    @validate_call(config=dict(validate_by_alias=False))+    def foo(a: Annotated[int, Field(alias='b')]):+        return a++    assert foo(a=1) == 1++    with pytest.raises(ValidationError):+        foo(b=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  

What the agent reported

@validate_call now honours populate_by_name=True and validate_by_alias=False. The new regression tests failed before the fix and pass after it, and the related test files all pass.

What was wrong: _arguments_schema() and _arguments_v3_schema() in pydantic/_internal/_generate_schema.py put the raw validate_by_name config key into the arguments schema. Two older settings are translated only inside ConfigWrapper.core_config(): populate_by_name becomes validate_by_name, and validate_by_alias=False implies validate_by_name=True. pydantic-core prefers the value in the schema over the core config, so the translated value was never used. Models aren't affected because their schema doesn't carry this flag.

What I changed:

  • pydantic/_internal/_config.py: new private property ConfigWrapper._effective_validate_by_name. It works out validate_by_name using the same order as core_config():
  • An explicit validate_by_name wins.
  • Otherwise populate_by_name is used.
  • Otherwise it is True when validate_by_alias is False, and False if not.
  • pydantic/_internal/_generate_schema.py: both places (lines 2081 and 2149) now use that property instead of the raw key.
  • Tests added:
  • test_populate_by_name and test_validate_by_alias_false in tests/test_validate_call.py.
  • test_arguments_v3_populate_by_name in tests/test_experimental_arguments_schema.py. It builds the validator without a config, so the value can only come from the schema.

Test evidence:

  • Before the fix: all three new tests failed.
  • f(a=10, d=1) gave "Unexpected keyword argument".
  • validate_by_alias=False raised "validate_by_name and validate_by_alias cannot both be set to False", so the parameter couldn't be passed at all.
  • The arguments-v3 version gave "Extra inputs are not permitted".
  • After the fix: ./bt-test on tests/test_validate_call.py, tests/test_experimental_arguments_schema.py, tests/test_config.py, tests/test_aliases.py and tests/test_dataclasses.py gave 548 passed, 35 skipped, 1 xfailed, 0 failed. No existing test was changed.
  • Lint: ruff isn't installed here, so I couldn't run it. I checked line lengths by hand and wrapped the one new line over 120 characters.
  • Review: the reviewer found no issues and confirmed the new property gives the same result as core_config() in every combination checked.

Requirements:

  1. populate_by_name=True lets you pass the parameter by name or by alias: done. test_populate_by_name covers the report's f(b=1) / f(a=1) case, and test_arguments_v3_populate_by_name covers the arguments-v3 path.
  2. validate_by_alias=False turns on validation by name: done. test_validate_by_alias_false checks that foo(a=1) works and foo(b=1) raises ValidationError.
  3. The docs say populate_by_name equals validate_by_name=True, validate_by_alias=True: covered. The fix reuses core_config()'s existing translation and doesn't add a new rule.
  4. Models are unaffected: confirmed. No model code changed, and tests/test_config.py and tests/test_aliases.py still pass.

Model and dataclass signature building (_model_construction.py:672, _dataclasses.py:158) still reads the raw validate_by_name key. That's separate from this bug, so I left it alone.

All changes are uncommitted in the working tree, and there are no scratch files.