Backtestspydanticrun-20261007-130130#13675

Issue #13675 Merged fix PR #13676 Run 7 Oct 2026 · run-20261007-130130 pydantic/pydantic

TypeAdapter config not used for JSON Schema generation

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 reported case the same way. They push the adapter's `_config` onto the generator's `_config_wrapper_stack` around `generate()` in `TypeAdapter.json_schema`. That addresses the root cause: the TypeAdapter config is not part of the core schema, so the JSON Schema generator never saw it. Patch B also fixes the sibling entry point, `TypeAdapter.json_schemas()`, which has the same defect. That path calls `generate_definitions` with core schemas only, so per-adapter configs (e.g. `ser_json_bytes='base64'`) would still be ignored there. B passes a per-input config list and pushes each config in both passes of `generate_definitions` (the definition-collection pass and the remap pass), so `$defs` and the top-level schemas stay consistent. Pushing `None` is a no-op on the stack, so the default path is unchanged. On tests, A adds one test, for `list[bytes]` with `ser_json_bytes`; it would fail before the fix and is adequate. B covers the exact issue example, a no-config control case, `ser_json_temporal`, `json_schema_mode_override` (which takes effect through the stack-aware mode lookup), and the `json_schemas` multi-adapter path with mixed configs. B's tests exercise more of the behaviour the fix enables. B's extra mutable `_inputs_configs` attribute on the generator is slightly awkward as a side channel, but it is private and defaults safely. Overall, B resolves the issue more completely across both TypeAdapter schema APIs and tests it more thoroughly.

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

7m 38s

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

53vs 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+48 −5
pydantic/json_schema.pyindex e7abcad0..eb77516a 100644@@ -285,6 +285,9 @@ class GenerateJsonSchema:          self.definitions: dict[DefsRef, JsonSchemaValue] = {}         self._config_wrapper_stack = _config.ConfigWrapperStack(_config.ConfigWrapper({}))+        # Configs to apply to each of the inputs passed to `generate_definitions()` (by index),+        # e.g. the configs of the type adapters in `TypeAdapter.json_schemas()`:+        self._inputs_configs: Sequence[ConfigDict | None] | None = None          self._mode: JsonSchemaMode = 'validation' @@ -379,16 +382,18 @@ class GenerateJsonSchema:                 code='json-schema-already-used',             ) -        for _, mode, schema in inputs:+        for i, (_, mode, schema) in enumerate(inputs):             self._mode = mode-            self.generate_inner(schema)+            with self._config_wrapper_stack.push(self._get_input_config(i)):+                self.generate_inner(schema)          definitions_remapping = self._build_definitions_remapping()          json_schemas_map: dict[tuple[JsonSchemaKeyT, JsonSchemaMode], DefsRef] = {}-        for key, mode, schema in inputs:+        for i, (key, mode, schema) in enumerate(inputs):             self._mode = mode-            json_schema = self.generate_inner(schema)+            with self._config_wrapper_stack.push(self._get_input_config(i)):+                json_schema = self.generate_inner(schema)             json_schemas_map[(key, mode)] = definitions_remapping.remap_json_schema(json_schema)          json_schema = {'$defs': self.definitions}@@ -396,6 +401,11 @@ class GenerateJsonSchema:         self._used = True         return json_schemas_map, self.sort(json_schema['$defs'])  # type: ignore +    def _get_input_config(self, index: int) -> ConfigDict | None:+        if self._inputs_configs is None:+            return None+        return self._inputs_configs[index]+     def generate(self, schema: CoreSchema, mode: JsonSchemaMode = 'validation') -> JsonSchemaValue:         """Generates a JSON schema for a specified schema in a specified mode. pydantic/type_adapter.pyindex 447ac34b..0869572f 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(@@ -785,6 +786,7 @@ class TypeAdapter(Generic[T]):         )          inputs_ = []+        inputs_configs: list[ConfigDict | None] = []         for key, mode, adapter in inputs:             # This is the same pattern we follow for model json schemas - we attempt a core schema rebuild if we detect a mock             if isinstance(adapter.core_schema, _mock_val_ser.MockCoreSchema):@@ -793,7 +795,9 @@ class TypeAdapter(Generic[T]):                     'this is a bug! please report it'                 )             inputs_.append((key, mode, adapter.core_schema))+            inputs_configs.append(adapter._config) +        schema_generator_instance._inputs_configs = inputs_configs         json_schemas_map, definitions = schema_generator_instance.generate_definitions(inputs_)          json_schema: dict[str, Any] = {}tests/test_type_adapter.pyindex ad746451..715f8b5d 100644@@ -1,6 +1,7 @@ import json from dataclasses import dataclass from datetime import date, datetime+from decimal import Decimal from typing import Annotated, Any, ForwardRef, Generic, NamedTuple, TypeAlias, TypeVar, Union  import pytest@@ -555,6 +556,34 @@ def test_ta_config_with_annotated_type() -> None:     ]  +def test_json_schema_uses_config() -> None:+    ta = TypeAdapter(bytes, config={'ser_json_bytes': 'base64'})+    assert ta.json_schema() == {'type': 'string', 'format': 'base64url'}+    assert TypeAdapter(bytes).json_schema() == {'type': 'string', 'format': 'binary'}++    ta_date = TypeAdapter(date, config={'ser_json_temporal': 'seconds'})+    assert ta_date.json_schema(mode='serialization') == {'type': 'number'}++    ta_override = TypeAdapter(Decimal, config={'json_schema_mode_override': 'serialization'})+    assert TypeAdapter(Decimal).json_schema(mode='validation') != TypeAdapter(Decimal).json_schema(mode='serialization')+    assert ta_override.json_schema(mode='validation') == TypeAdapter(Decimal).json_schema(mode='serialization')+++def test_json_schemas_uses_each_adapter_config() -> None:+    json_schemas_map, _ = TypeAdapter.json_schemas(+        [+            ('base64', 'validation', TypeAdapter(bytes, config={'ser_json_bytes': 'base64'})),+            ('default', 'validation', TypeAdapter(bytes)),+            ('seconds', 'serialization', TypeAdapter(datetime, config={'ser_json_temporal': 'seconds'})),+        ]+    )+    assert json_schemas_map == {+        ('base64', 'validation'): {'type': 'string', 'format': 'base64url'},+        ('default', 'validation'): {'type': 'string', 'format': 'binary'},+        ('seconds', 'serialization'): {'type': 'number'},+    }++ def defer_build_test_models(config: ConfigDict) -> list[Any]:     class Model(BaseModel):         model_config = config 
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