Backtestspydanticrun-20260929-204949#13687

Issue #13687 Merged fix PR #13691 Run 29 Sep 2026 · run-20260929-204949 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 address the root cause—that the arguments schema embeds a raw `validate_by_name` value that bypasses the backwards-compat mapping done in `core_config()`. Patch B fixes it narrowly by reading the value from `core_config()` at the two embedding sites (good DRY: single source of truth for the mapping). Patch A adds a `validate_by_name` property on ConfigWrapper that centralizes the three rules (explicit flag, populate_by_name alias, and the #11503 implicit validate_by_alias=False→True), so every reader of `.validate_by_name` gets the correct value. Both resolve the primary populate_by_name scenario. The deciding factors are tests and scope. The issue explicitly calls out a 'worse variant': `validate_by_alias=False` making the parameter impossible to provide. Patch A adds a dedicated `test_validate_by_alias_false` covering exactly that scenario (plus a thorough populate_by_name matrix), so both reported behaviors are pinned. Patch B only tests `populate_by_name`; it never adds a test for the validate_by_alias=False variant despite it being a distinct code path (the implicit-enable logic), leaving that scenario unverified. Patch B also introduces unrelated churn—rewriting `dict(...)` to `{...}` in test_validate_return and test_validate_all, which are untouched by the fix. Patch A's mild downside is duplicating the mapping logic that also lives in core_config(), a minor maintainability concern, but that is outweighed by its complete test coverage of both issue scenarios and its lack of extraneous edits.

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

12m 11s24 turns

Wall-clock time in the container

Full test suite

No new failures

12,394 passed · 500 skipped · 12,894 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

37vs 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+37 −0
pydantic/_internal/_config.pyindex 5fcfe38a..3bd3568a 100644@@ -185,6 +185,22 @@ class ConfigWrapper:                 except KeyError:                     raise AttributeError(f'Config has no attribute {name!r}') from None +        @property+        def validate_by_name(self) -> bool:+            config = self.config_dict+            validate_by_name = config.get('validate_by_name')+            if validate_by_name is not None:+                return validate_by_name+            # Backwards-compatible mapping: `populate_by_name` is a deprecated alias+            # for `validate_by_name` (see `core_config`).+            if (populate_by_name := config.get('populate_by_name')) is not None:+                return populate_by_name+            # `validate_by_name` is implicitly enabled when `validate_by_alias` is+            # disabled and `validate_by_name` was not explicitly set (see #11503).+            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. tests/test_validate_call.pyindex de86f03a..96eba24c 100644@@ -929,6 +929,27 @@ def test_validate_by_name():     assert foo(a=10, c=1) == 11  +def test_validate_by_name_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

Done. The working tree contains only the intended production fix and the regression tests.

What was wrong

Since v2.11, @validate_call(config=...) ignored two alias-related config settings that work fine on BaseModel:

  • populate_by_name=True — the aliased parameter could no longer be passed by its field name.
  • validate_by_alias=False — the aliased parameter became impossible to provide at all (both name and alias raised), even though validate_by_alias=False is supposed to implicitly enable validate_by_name (#11503).

Root cause: GenerateSchema._arguments_schema() and _arguments_v3_schema() (pydantic/_internal/_generate_schema.py:2081 / :2149) embed validate_by_name=self._config_wrapper.validate_by_name into the core schema, reading the raw config value (default False). The backwards-compat mapping (populate_by_name → validate_by_name, and the implicit-name rule for validate_by_alias=False) only ran inside ConfigWrapper.core_config(), and pydantic-core gives the schema-embedded flag precedence — so the patched value was never consulted. Models were unaffected because core_config() mutates the config dict in place before their readers run.

What I changed

pydantic/_internal/_config.py — turned ConfigWrapper.validate_by_name into a computed property (inside the existing if not TYPE_CHECKING: block, so the validate_by_name: bool annotation kept in sync with ConfigDict is untouched). It applies the same precedence as core_config(): explicit validate_by_name wins → else populate_by_name → else True when validate_by_alias is False → else default False. Now every reader — including the two arguments-schema call sites — gets the effective value; the call sites themselves were left unchanged. core_config() was not touched, so its PydanticUserError for the both-explicitly-False case still fires.

Test evidence

  • Added test_validate_by_name_populate_by_name and test_validate_by_alias_false to tests/test_validate_call.py. Both failed before the fix (ValidationError / ValueError: ...cannot both be set to False) and pass after.
  • Gate: ./bt-test tests/test_validate_call.py tests/test_config.py → 149 passed, 0 failed (incl. the annotation-sync test in test_config.py).
  • Blast radius (property now feeds model/dataclass signature generation too): ./bt-test tests/test_main.py tests/test_dataclasses.py tests/test_aliases.py -k "alias or by_name or populate or validate_by" → 128 passed, 32 skipped, 0 failed.
  • Original report snippet re-run: f(a=1) and f(b=1) both return 1; g(a=1) returns 1 and g(b=1) raises ValidationError — exactly the expected outcomes.
  • Reviewer confirmed the fix addresses both scenarios, matches core_config() precedence, changes nothing unrelated, and weakens no tests.

Requirements disposition

  1. populate_by_name=True must allow passing the aliased param by name — ✅ Implemented; covered by test_validate_by_name_populate_by_name (fails before, passes after).
  2. validate_by_alias=False must implicitly enable validate_by_name (param providable by name, alias rejected) — ✅ Implemented; covered by test_validate_by_alias_false (fails before, passes after).
  3. Models must remain unaffected — ✅ Verified via model/dataclass/alias test runs (all pass); core_config() untouched.
  4. ConfigDict↔ConfigWrapper annotation sync preserved — ✅ Verified; test_config.py annotation-sync test passes.