Backtestspydanticrun-20260930-183947#13687

Issue #13687 Merged fix PR #13691 Run 30 Sep 2026 · run-20260930-183947 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 `validate_by_name` config value was being embedded into the arguments and arguments-v3 schemas.

Patch A reads the value from `core_config()`, which already applies the `populate_by_name` mapping and the implicit `validate_by_alias=False` → `validate_by_name=True` rule. This keeps one source of truth, which is good craft.

Patch B adds an `effective_validate_by_name` property that repeats the precedence logic from `core_config()`. The two copies could drift apart later, but the logic currently matches, including explicit `validate_by_name` overriding `populate_by_name`. B also applies the property to model and dataclass signature generation. That is an adjacent fix of the same bug class, low risk and covered by its own tests, so it is neutral.

On correctness, both handle the two scenarios in the issue: `populate_by_name=True`, and `validate_by_alias=False` making the parameter impossible to provide.

The tests differ clearly:
- **Patch A** only tests `populate_by_name=True`, via `validate_call` and an arguments-v3 schema. It never exercises the "worse variant" (`validate_by_alias=False`) that the issue calls out. It also makes unrelated style edits (`dict(...)` → `{...}`) to existing tests.
- **Patch B** parametrizes over both configs and both schema types (arguments and arguments-v3). It checks that the alias is rejected when `validate_by_alias=False`, and tests the precedence between explicit `validate_by_name` and `populate_by_name` in both directions. It also covers the signature change.

B's tests would fail before the fix and pass after for every scenario in the issue, while A's miss one. That outweighs A's slightly cleaner single-source implementation, so 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

9m 39s

Wall-clock time in the container

Full test suite

No new failures

12,401 passed · 500 skipped · 12,901 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

102vs 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+98 −4
pydantic/_internal/_config.pyindex 5fcfe38a..fb8c325f 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 the backwards compatible `populate_by_name` setting+        and the implicit `validate_by_name=True` when `validate_by_alias` is set to `False`.++        This mirrors the logic applied in `core_config()`, and should be used instead of the raw+        `validate_by_name` attribute when the value is embedded directly in a core schema.+        """+        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+        if config.get('validate_by_alias') is False:+            return True+        return config_defaults['validate_by_name']+     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..7d6a231c 100644@@ -186,3 +186,23 @@ 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_validate_by_name_implicit(schema_type: Literal['arguments', 'arguments-v3'], config: Any) -> None:+    """`populate_by_name=True` and `validate_by_alias=False` both imply `validate_by_name=True`."""++    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)+    input = ArgsKwargs((), {'a': 1}) if schema_type == 'arguments' else {'a': 1}+    assert val.validate_python(input) == ((), {'a': 1})tests/test_model_signature.pyindex 04801a23..0058fa32 100644@@ -102,6 +102,22 @@ def test_use_field_name():     assert _equals(str(signature(Foo)), '(*, foo: str) -> None')  +@pytest.mark.parametrize(+    'config',+    [+        ConfigDict(populate_by_name=True),+        ConfigDict(validate_by_alias=False),+    ],+)+def test_use_field_name_implicit_validate_by_name(config: ConfigDict):+    class Foo(BaseModel):+        foo: str = Field(alias='this is invalid')++        model_config = config++    assert _equals(str(signature(Foo)), '(*, foo: str) -> None')++ def test_does_not_use_reserved_word():     class Foo(BaseModel):         from_: str = Field(alias='from')tests/test_validate_call.pyindex de86f03a..6f5f2f4d 100644@@ -929,6 +929,47 @@ 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: dict[str, Any]) -> 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')]) -> int:+        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=r'b\s+Unexpected keyword argument'):+            foo(b=1)+++def test_populate_by_name_false_explicit_validate_by_name() -> None:+    """An explicit `validate_by_name` takes precedence over `populate_by_name`."""++    @validate_call(config=dict(populate_by_name=False, validate_by_name=True))+    def foo(a: Annotated[int, Field(alias='b')]) -> int:+        return a++    assert foo(a=1) == 1+    assert foo(b=1) == 1++    @validate_call(config=dict(populate_by_name=True, validate_by_name=False))+    def bar(a: Annotated[int, Field(alias='b')]) -> int:+        return a++    assert bar(b=1) == 1+    with pytest.raises(ValidationError, match=r'a\s+Unexpected keyword argument'):+        bar(a=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