fix: handle boolean JSON Schema nodes in JsonSchemaTransformer#4989
fix: handle boolean JSON Schema nodes in JsonSchemaTransformer#4989Dharit13 wants to merge 1 commit intopydantic:mainfrom
JsonSchemaTransformer#4989Conversation
495c662 to
6f83a4b
Compare
Boolean JSON Schema nodes (`true`/`false`) are valid per the spec but caused an `AttributeError` in the schema walker which unconditionally called `.get()` on every child node. Treat booleans as terminal leaves so the walker passes them through untouched. Closes pydantic#4771 Made-with: Cursor
6f83a4b to
77e1b98
Compare
There was a problem hiding this comment.
🚩 OpenAI transformer's result.update(self.defs.get(root_key) or {}) is fragile with widened defs type
The PR widens self.defs from dict[str, JsonSchema] to dict[str, _JsonSchemaNode] at pydantic_ai_slim/pydantic_ai/_json_schema.py:49. The OpenAIJsonSchemaTransformer.walk() at pydantic_ai_slim/pydantic_ai/profiles/openai.py:251 does result.update(self.defs.get(root_key) or {}). If root_key maps to True, True or {} evaluates to True, and result.update(True) raises TypeError: 'bool' object is not iterable. If it maps to False, False or {} silently produces {}, losing the false schema semantics. This is only reachable if a root-level $ref points to a boolean $def, which pydantic never generates — so it's a theoretical concern rather than a practical one. But the type system now claims to support it.
(Refers to line 49)
Was this helpful? React with 👍 or 👎 to provide feedback.
|
Re: Devin Review comment on This was addressed in the latest push. Boolean schema nodes only appear inline (as property values, array items, union members) and are handled as terminal leaves in The |
Summary
JsonSchemaTransformer.walk()crashes withAttributeError: 'bool' object has no attribute 'get'when a JSON Schema contains boolean schema nodes (e.g."value": true). Boolean schemas are valid per the JSON Schema spec (trueis equivalent to{},falseis equivalent to{"not": {}}), but the walker unconditionally called.get()on every child node assuming it was a dict.This PR treats boolean schema nodes as terminal leaves in the internal walker so they pass through untouched, and adds a parametrized regression test covering both
TrueandFalse.Pre-Review Checklist
make formatandmake typecheck.Pre-Merge Checklist
Made with Cursor