Backtestspydanticrun-20260923-170312#13675
TypeAdapter config not used for JSON Schema generation
The merged fix was judged better than our patch.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches make byte-for-byte the same root-cause fix: pushing self._config onto the generator's _config_wrapper_stack so the TypeAdapter's config reaches JSON Schema generation. Correctness and scope are therefore identical — both resolve the issue at its source rather than masking a symptom, and neither has extraneous churn. The decision falls to tests and craft. On tests they are roughly equivalent in strength: A's parametrized test (base64->base64url, utf8->binary) mirrors the issue's exact bytes reproduction and asserts both config values, while B's test uses list[bytes] to prove the config also propagates through a container type and links the tracking issue; both would fail before and pass after, so neither is decisively stronger. The tiebreaker is craft: B adds a clear comment explaining the non-obvious reason for the fix (the config is not part of the core schema and must be made available to the generator explicitly), which is exactly the kind of documentation that prevents future regressions of this subtle behavior, plus an issue-number reference. A leaves the change unexplained. Given identical correctness/scope and comparable tests, B's explanatory comment and container-propagation test edge it out.
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
13m 17s16 turns
Wall-clock time in the container
Full test suite
No new failures
6,593 passed · 367 skipped · 6,960 total
Contamination audit
Unknown
See the audit notes for this run
Patch size
15vs 11 merged
Changed lines, ours vs merged
The issue
View on GitHubfrom 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
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..c21f549d 100644@@ -2047,6 +2047,18 @@ def test_typeddict_default_bytes(ser_json_bytes: Literal['base64', 'utf8'], prop } +@pytest.mark.parametrize(+ 'ser_json_bytes,schema',+ [+ ('base64', {'format': 'base64url', 'type': 'string'}),+ ('utf8', {'format': 'binary', 'type': 'string'}),+ ],+)+def test_type_adapter_default_bytes(ser_json_bytes: Literal['base64', 'utf8'], schema: dict[str, Any]):+ # insert_assert(TypeAdapter(bytes, config=ConfigDict(ser_json_bytes=ser_json_bytes)).json_schema())+ assert TypeAdapter(bytes, config=ConfigDict(ser_json_bytes=ser_json_bytes)).json_schema() == schema++ def test_model_subclass_metadata(): class A(BaseModel): """A Model docstring"""
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 fix is complete and verified. Here is my final report.
What was wrong
TypeAdapter.json_schema() ignored the adapter's own config. GenerateJsonSchema reads config from self._config_wrapper_stack.tail, and that stack is only populated when the generator traverses into a model/dataclass/TypedDict node (each pushes its config). For a bare top-level type like bytes, nothing was ever pushed, so TypeAdapter(bytes, config={'ser_json_bytes': 'base64'}).json_schema() fell back to the default config and produced format: 'binary' instead of 'base64url' — unlike a BaseModel, whose config is pushed during traversal.
What I changed
pydantic/type_adapter.py — in TypeAdapter.json_schema(), wrapped the final generate call to push the adapter's config onto the generator's stack, mirroring what the model/dataclass/TypedDict handlers do during traversal:
with schema_generator_instance._config_wrapper_stack.push(self._config):
return schema_generator_instance.generate(self.core_schema, mode=mode)
ConfigWrapperStack.push accepts ConfigDict | None and is a no-op for None, so config-less adapters are unaffected. It sits at the bottom of the stack, so any inner type's own config still correctly overrides it.
tests/test_json_schema.py — added test_type_adapter_default_bytes, parametrized over ser_json_bytes ('base64' → base64url, 'utf8' → binary), asserting on the report's exact call TypeAdapter(bytes, config=ConfigDict(...)).json_schema().
Test evidence
- Before fix: the new test FAILED on the
base64case ({'format': 'binary'} != {'format': 'base64url'}) — confirming the reported bug. - After fix: full run of
tests/test_json_schema.py+tests/test_type_adapter.py→ 776 passed, 3 skipped, 2 xfailed, including the new regression test. No previously passing tests regressed. - Reviewer confirmed the fix is correct, minimal, and free of blast-radius issues (configured types can't take a
configarg, so their behavior is unchanged; inner config still overrides).
Requirements checklist
TypeAdapter(bytes, config={'ser_json_bytes': 'base64'}).json_schema()must honor config (returnbase64url) — ✅ Implemented and covered by the passing regression test.
The report described a single behavior. One adjacent item surfaced during review, disposed with evidence:
TypeAdapter.json_schemas()(the multi-adapter static method) has the same gap — Skipped. Evidence: it usesgenerate_definitionsand does not push per-adapter config (type_adapter.py:742-808). This is a pre-existing issue outside the report's scope (the report only concerns.json_schema()), so I left it untouched to keep the change minimal.
All changes are left uncommitted in the working tree.