Commit 9453731
committed
Fix compatibility with pydantic 2.12+ Field defaults in Annotated types
When using Annotated[T, Field(default)] without an explicit parameter
default (= value), pydantic 2.12+ changed FieldInfo.from_annotated_attribute()
to overwrite the Field's default with PydanticUndefined, incorrectly marking
fields as required in the JSON schema.
This fix checks if a Field with a default exists in the Annotated metadata
and uses FieldInfo.from_annotation() to preserve that default, while still
using from_annotated_attribute() for the standard case where parameter
defaults take precedence.
The fix maintains backward compatibility with pydantic 2.11 and earlier
while ensuring correct behavior with 2.12+.1 parent da4fce2 commit 9453731
1 file changed
+21
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
239 | 239 | | |
240 | 240 | | |
241 | 241 | | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
246 | 263 | | |
247 | 264 | | |
248 | 265 | | |
| |||
0 commit comments