Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pydantic_ai_slim/pydantic_ai/models/gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def simplify(self) -> dict[str, Any]:

def _simplify(self, schema: dict[str, Any], refs_stack: tuple[str, ...]) -> None:
schema.pop('title', None)
default = schema.pop('default', _utils.UNSET)
schema.pop('default', None)
Copy link
Contributor Author

@dmontagu dmontagu Jan 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure why we are currently requiring the default to be None in order to remove the the {'type': 'null'} from the schema, that condition doesn't seem to me to be necessary, so I removed it here. (And we don't use the value of the default at all, so I removed the variable that was holding its value, and changed the .pop call to fall back to None to be consistent with the previous line which is also unused.)

if ref := schema.pop('$ref', None):
# noinspection PyTypeChecker
key = re.sub(r'^#/\$defs/', '', ref)
Expand All @@ -708,11 +708,12 @@ def _simplify(self, schema: dict[str, Any], refs_stack: tuple[str, ...]) -> None
if any_of := schema.get('anyOf'):
for item_schema in any_of:
self._simplify(item_schema, refs_stack)
if len(any_of) == 2 and {'type': 'null'} in any_of and default is None:
if len(any_of) == 2 and {'type': 'null'} in any_of:
for item_schema in any_of:
if item_schema != {'type': 'null'}:
schema.clear()
schema.update(item_schema)
schema['nullable'] = True
return

type_ = schema.get('type')
Expand Down
1 change: 1 addition & 0 deletions tests/models/test_gemini.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ class Locations(BaseModel):
'lng': {'type': 'number'},
},
'required': ['lat', 'lng'],
'nullable': True,
'type': 'object',
}
},
Expand Down
Loading