Backtestspydanticrun-20260929-204949#13675

Issue #13675 Merged fix PR #13676 Run 29 Sep 2026 · run-20260929-204949 pydantic/pydantic

TypeAdapter config not used for JSON Schema generation

Worse

The merged fix was judged better than our patch.

In this judgment, Patch B = our agent, Patch A = the merged fix.

The core fix is identical in both patches: wrap generation in `schema_generator_instance._config_wrapper_stack.push(self._config)` to make the TypeAdapter's config available to the JSON Schema generator. Both correctly address the root cause and would pass their added tests while failing before. On tests, they are close: B parametrizes both base64->base64url and utf8->binary (directly mirroring the issue's example), while A tests a nested list[bytes] proving the config propagates through recursion. These are comparable in value. The deciding factor is craft: A adds an explanatory comment clarifying why the config must be explicitly pushed (it is not part of the core schema), which documents a non-obvious mechanism at the edit site; B leaves the change unexplained. With correctness, scope, and test value effectively even, A's clearer documentation gives it a slight edge.

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

4m 13s17 turns

Wall-clock time in the container

Full test suite

No new failures

12,372 passed · 500 skipped · 12,872 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

16vs 11 merged

Changed lines, ours vs merged

from pydantic import BaseModel, TypeAdapter

class Model(BaseModel, ser_json_bytes='base64'):
    b: bytes

Model.model_json_schema()['properties']['b']
#> {'format': 'base64url', 'title': 'B', 'type': 'string'}

ta = TypeAdapter(bytes, config={'ser_json_bytes': 'base64'})
ta.json_schema()
#> {'format': 'binary', 'type': 'string'}

The two patches

Our patch+15 −1
pydantic/type_adapter.pyindex 447ac34b..e9f16311 100644@@ -736,7 +736,8 @@ class TypeAdapter(Generic[T]):         if isinstance(self.core_schema, _mock_val_ser.MockCoreSchema):             self.core_schema.rebuild()             assert not isinstance(self.core_schema, _mock_val_ser.MockCoreSchema), 'this is a bug! please report it'-        return schema_generator_instance.generate(self.core_schema, mode=mode)+        with schema_generator_instance._config_wrapper_stack.push(self._config):+            return schema_generator_instance.generate(self.core_schema, mode=mode)      @staticmethod     def json_schemas(tests/test_json_schema.pyindex f7533631..4a643033 100644@@ -2047,6 +2047,19 @@ def test_typeddict_default_bytes(ser_json_bytes: Literal['base64', 'utf8'], prop     }  +@pytest.mark.parametrize(+    'ser_json_bytes,expected_format',+    [+        ('base64', 'base64url'),+        ('utf8', 'binary'),+    ],+)+def test_type_adapter_config_bytes(ser_json_bytes: Literal['base64', 'utf8'], expected_format: str):+    ta = TypeAdapter(bytes, config=ConfigDict(ser_json_bytes=ser_json_bytes))++    assert ta.json_schema() == {'type': 'string', 'format': expected_format}++ def test_model_subclass_metadata():     class A(BaseModel):         """A Model docstring""" 
Merged fix · PR #13676+10 −1
pydantic/type_adapter.pyindex 447ac34bc..1c6824acb 100644@@ -736,7 +736,10 @@ class TypeAdapter(Generic[T]):         if isinstance(self.core_schema, _mock_val_ser.MockCoreSchema):             self.core_schema.rebuild()             assert not isinstance(self.core_schema, _mock_val_ser.MockCoreSchema), 'this is a bug! please report it'-        return schema_generator_instance.generate(self.core_schema, mode=mode)+        # The configuration provided to the type adapter (if any) is not part of the core schema,+        # so we need to explicitly make it available to the JSON Schema generator:+        with schema_generator_instance._config_wrapper_stack.push(self._config):+            return schema_generator_instance.generate(self.core_schema, mode=mode)      @staticmethod     def json_schemas(tests/test_type_adapter.pyindex ad7464513..1038a8291 100644@@ -555,6 +555,12 @@ def test_ta_config_with_annotated_type() -> None:     ]  +def test_ta_config_used_for_json_schema() -> None:+    """https://github.com/pydantic/pydantic/issues/13675"""+    ta = TypeAdapter(list[bytes], config=ConfigDict(ser_json_bytes='base64'))+    assert ta.json_schema() == {'type': 'array', 'items': {'type': 'string', 'format': 'base64url'}}++ def defer_build_test_models(config: ConfigDict) -> list[Any]:     class Model(BaseModel):         model_config = config 

What the agent reported

The review confirms the fix is correct, minimal, and complete. Done.

Summary

What was wrong: TypeAdapter.json_schema() never threaded the adapter's config into JSON Schema generation. It created a GenerateJsonSchema instance whose config-wrapper stack held only an empty default ConfigWrapper({}). For a bare type like bytes, nothing ever pushed the adapter's config onto that stack (only the model/dataclass/typeddict handlers push config, which is why BaseModel worked). So bytes_schema read the default ser_json_bytes='utf8' and emitted format: 'binary' instead of 'base64url'.

What I changed (pydantic/type_adapter.py, json_schema()): wrapped the generate() call in with schema_generator_instance._config_wrapper_stack.push(self._config):, so the adapter's config becomes the stack tail during generation. ConfigWrapperStack.push is a no-op when passed None, so the class-based case (where self._config is always None — a config for a BaseModel/dataclass/TypedDict raises at construction) is unaffected.

Test evidence:

  • Added test_type_adapter_config_bytes in tests/test_json_schema.py, mirroring the existing test_*_default_bytes idiom, parametrized base64 → base64url (the reported bug) and utf8 → binary.
  • Confirmed it failed before the fix (assert {'format': 'binary'} == {'format': 'base64url'}) and passes after.
  • Gate: ./bt-test tests/test_json_schema.py tests/test_type_adapter.py → 776 passed, 3 skipped, 2 xfailed (skips/xfails pre-existing). No previously passing test regressed — the blast radius (all TypeAdapter.json_schema callers) is covered by these suites.
  • Reviewer confirmed correctness, minimality, no unrelated changes, no scratch files.

Requirements disposition:

  1. TypeAdapter(config=...) config must drive JSON Schema generation (specifically ser_json_bytes='base64' → base64url) — Implemented, with a passing regression test that was verified failing before the change. The fix also correctly propagates other serialization-config fields (e.g. ser_json_timedelta), consistent with the model/dataclass path.

Changes left uncommitted in the working tree.