Backtestspydanticrun-20260930-144322#13675

Issue #13675 Merged fix PR #13676 Run 30 Sep 2026 · run-20260930-144322 pydantic/pydantic

TypeAdapter config not used for JSON Schema generation

Par

Our patch was judged on par with the merged fix.

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

The functional change is identical in both patches. Each wraps `schema_generator_instance.generate(...)` in `_config_wrapper_stack.push(self._config)` inside `TypeAdapter.json_schema`. This fixes the root cause: the adapter's config is not part of the core schema, so the JSON Schema generator never saw settings like `ser_json_bytes`. Correctness is therefore equal.

Both tests would fail before the fix and pass after it.
- Patch A reproduces the issue's exact scenario (`TypeAdapter(bytes)` with `ser_json_bytes='base64'` yields `format: base64url`). It also checks the default `binary` output as a baseline, confirming the default is unchanged.
- Patch B tests `list[bytes]`, showing the config reaches nested items. It skips the default-case check.

Neither test is clearly stronger; they cover slightly different angles of equal value. Scope is minimal and equivalent in both. On craft, Patch B adds a brief comment explaining why the push is needed, a small plus that is offset by Patch A's baseline assertion. No meaningful difference remains overall.

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 18s12 turns

Wall-clock time in the container

Full test suite

No new failures

12,371 passed · 500 skipped · 12,871 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

11vs 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+10 −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_type_adapter.pyindex ad746451..53007049 100644@@ -555,6 +555,14 @@ def test_ta_config_with_annotated_type() -> None:     ]  +def test_ta_config_applied_to_json_schema() -> None:+    assert TypeAdapter(bytes).json_schema() == {'type': 'string', 'format': 'binary'}+    assert TypeAdapter(bytes, config=ConfigDict(ser_json_bytes='base64')).json_schema() == {+        'type': 'string',+        'format': 'base64url',+    }++ 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 

What the agent reported

TypeAdapter.json_schema() now uses the adapter's config, so TypeAdapter(bytes, config={'ser_json_bytes': 'base64'}).json_schema() returns {'type': 'string', 'format': 'base64url'}. That matches what BaseModel produces. The new regression test failed before the fix and passes after it. The changes are uncommitted in the working tree.

What was wrong: the JSON schema generator picks the bytes format from its current config (pydantic/json_schema.py:817). That config starts out empty. Models, dataclasses and TypedDicts apply their own config while their schema is generated, but TypeAdapter.json_schema() never passed its config in. So the generator always used the default, 'binary'.

What I changed (pydantic/type_adapter.py:739): the adapter's config is now applied around the generate(...) call. When no config is given, nothing changes. An adapter can't have a config if the type already carries one (the constructor raises), so models keep using their own config.

Tests:

  • New test: tests/test_type_adapter.py::test_ta_config_applied_to_json_schema checks that the default stays 'binary' and that ser_json_bytes='base64' gives 'base64url'. Before the fix it failed with {'format': 'binary'} != {'format': 'base64url'}.
  • Nearby files: ./bt-test tests/test_type_adapter.py tests/test_json_schema.py gave 775 passed, 3 skipped, 2 xfailed, 0 failed.
  • Full suite: ./bt-test tests/ gave 11344 passed and 1 failed. The failure is tests/test_validators.py:1995, which compares file paths (/work/... vs /workspace/...). It fails the same way with my changes stashed, so it comes from the test environment.

Effect on existing users: any setting the schema generator reads from config now takes effect for a TypeAdapter, not just ser_json_bytes. That includes ser_json_temporal, ser_json_timedelta, json_schema_mode_override and json_schema_serialization_defaults_required. This is consistent with how models behave, and all existing tests pass. Anyone who was relying on those settings being ignored will see different schema output, so it deserves a changelog note.

Requirements:

  1. Adapter config applies in TypeAdapter.json_schema(): fixed, with the regression test above.
  2. The model and adapter give the same bytes format: the new test asserts 'base64url', which is what the report shows for the model. Existing model tests (test_model_default_bytes and similar) still pass.
  3. Default adapters still give 'binary': asserted in the same test.

Not fixed: the static TypeAdapter.json_schemas([...]) method still ignores each adapter's config. It builds all the adapters' schemas in one call to generate_definitions, which has no way to take a config per input. Fixing it would mean changing that function's interface, which is beyond this report's example and beyond a minimal fix. I didn't add a test for it; it's a reasonable follow-up.