Backtestspydanticrun-20261013-104308#13687

Issue #13687 Merged fix PR #13691 Run 13 Oct 2026 · run-20261013-104308 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. The bug is that the arguments schemas embed the raw `validate_by_name` value, which overrides the core config.

Patch A adds `ConfigWrapper.resolved_validate_by_name()`. It resolves an explicit `validate_by_name` first, then falls back to `populate_by_name`, and finally treats `validate_by_alias is False` as enabling name validation. It uses this in both `_arguments_schema` and `_arguments_v3_schema`. That handles both scenarios in the issue: `populate_by_name=True` and the 'worse variant' with `validate_by_alias=False`. A also applies the resolved value to the generated `__init__` signatures for models and dataclasses. That is adjacent and low-risk, and it keeps signatures consistent with validation behavior. The main weakness is that the logic duplicates what `core_config()` already does, so the two could drift apart; the docstring at least says so.

Patch B calls `core_config(title=None)` and embeds `core_config.get('validate_by_name')`. This reuses the existing patching logic as a single source of truth, which is clean. If that patching also covers the `validate_by_alias=False` case, B fixes both scenarios too, and an unset value passes through as None so pydantic-core falls back to its config. It does build a whole core config just to read one key, which is a little wasteful.

The deciding factor is the tests. A tests both issue scenarios for `@validate_call` and for both experimental schema types. It checks that the alias still works under `populate_by_name`, and that under `validate_by_alias=False` the name works and the alias is rejected with specific error types. B only tests the `populate_by_name` name path, only for `arguments-v3` plus one `validate_call` case. It never exercises the `validate_by_alias=False` variant the issue calls worse. B also adds unrelated test churn (rewriting `dict(...)` as `{...}` in existing tests) and leaves placeholder `"""<link>"""` docstrings.

Correctness is roughly equal, so A wins on test coverage of the reported scenarios and on cleaner scope in its tests.

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

6m 11s

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

76vs 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+72 −4
pydantic/_internal/_config.pyindex 5fcfe38a..d920d8d5 100644@@ -185,6 +185,23 @@ class ConfigWrapper:                 except KeyError:                     raise AttributeError(f'Config has no attribute {name!r}') from None +    def resolved_validate_by_name(self) -> bool:+        """Return the effective `validate_by_name` value, taking deprecated and implicit settings into account.++        This mirrors the patching done in [`core_config()`][pydantic._internal._config.ConfigWrapper.core_config]:+        `populate_by_name` maps to `validate_by_name` (if the latter isn't explicitly set), and+        `validate_by_alias=False` implicitly enables `validate_by_name` (if the latter isn't explicitly set).++        This should be used wherever the value is embedded directly into core schemas (e.g. arguments schemas)+        or signatures, as such values 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..0a4a5bda 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.resolved_validate_by_name(),             extra=config_wrapper.extra,             is_dataclass=True,         ),pydantic/_internal/_generate_schema.pyindex 54a11e09..c17ca854 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.resolved_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.resolved_validate_by_name(),         )      def _unsubstituted_typevar_schema(self, typevar: typing.TypeVar) -> core_schema.CoreSchema:pydantic/_internal/_model_construction.pyindex a6566209..2b141562 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.resolved_validate_by_name(),             extra=config_wrapper.extra,         ),     )tests/test_experimental_arguments_schema.pyindex 34ebf969..95172e33 100644@@ -84,6 +84,34 @@ def test_arguments_v3_alias_generator() -> None:     assert kwargs == {'a': 1}  +@pytest.mark.parametrize('schema_type', ['arguments', 'arguments-v3'])+def test_arguments_populate_by_name(schema_type: Literal['arguments', 'arguments-v3']) -> None:+    def func(*, a: Annotated[int, Field(alias='b')]) -> None: ...++    arguments_schema = generate_arguments_schema(func=func, schema_type=schema_type, config={'populate_by_name': True})+    val = SchemaValidator(arguments_schema)+    if schema_type == 'arguments':+        assert val.validate_python(ArgsKwargs((), {'a': 1})) == ((), {'a': 1})+        assert val.validate_python(ArgsKwargs((), {'b': 1})) == ((), {'a': 1})+    else:+        assert val.validate_python({'a': 1}) == ((), {'a': 1})+        assert val.validate_python({'b': 1}) == ((), {'a': 1})+++@pytest.mark.parametrize('schema_type', ['arguments', 'arguments-v3'])+def test_arguments_validate_by_alias_false(schema_type: Literal['arguments', 'arguments-v3']) -> None:+    def func(*, a: Annotated[int, Field(alias='b')]) -> None: ...++    arguments_schema = generate_arguments_schema(+        func=func, schema_type=schema_type, config={'validate_by_alias': False}+    )+    val = SchemaValidator(arguments_schema, config={'validate_by_alias': False})+    if schema_type == 'arguments':+        assert val.validate_python(ArgsKwargs((), {'a': 1})) == ((), {'a': 1})+    else:+        assert val.validate_python({'a': 1}) == ((), {'a': 1})++ def test_arguments_v3_kwargs_uniform() -> None:     def func(**kwargs: int) -> None: ... tests/test_validate_call.pyindex de86f03a..4f94414d 100644@@ -929,6 +929,29 @@ def test_validate_by_name():     assert foo(a=10, c=1) == 11  +@pytest.mark.parametrize(+    'schema_config', [{'populate_by_name': True}, {'validate_by_alias': True, 'populate_by_name': True}]+)+def test_populate_by_name(schema_config) -> None:+    @validate_call(config=schema_config)+    def foo(a: Annotated[int, Field(alias='b')]) -> int:+        return a++    assert foo(b=1) == 1+    assert foo(a=1) == 1+++def test_validate_by_alias_false_implies_validate_by_name() -> None:+    @validate_call(config=dict(validate_by_alias=False))+    def foo(a: Annotated[int, Field(alias='b')]) -> int:+        return a++    assert foo(a=1) == 1+    with pytest.raises(ValidationError) as exc_info:+        foo(b=1)+    assert [err['type'] for err 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