@@ -256,14 +256,15 @@ def model_dump(
256
256
mode : Literal ["json" , "python" ] | str = "python" ,
257
257
include : IncEx | None = None ,
258
258
exclude : IncEx | None = None ,
259
- by_alias : bool = False ,
259
+ by_alias : bool | None = None ,
260
260
exclude_unset : bool = False ,
261
261
exclude_defaults : bool = False ,
262
262
exclude_none : bool = False ,
263
263
round_trip : bool = False ,
264
264
warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
265
265
context : dict [str , Any ] | None = None ,
266
266
serialize_as_any : bool = False ,
267
+ fallback : Callable [[Any ], Any ] | None = None ,
267
268
) -> dict [str , Any ]:
268
269
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
269
270
@@ -295,10 +296,12 @@ def model_dump(
295
296
raise ValueError ("context is only supported in Pydantic v2" )
296
297
if serialize_as_any != False :
297
298
raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
299
+ if fallback is not None :
300
+ raise ValueError ("fallback is only supported in Pydantic v2" )
298
301
dumped = super ().dict ( # pyright: ignore[reportDeprecated]
299
302
include = include ,
300
303
exclude = exclude ,
301
- by_alias = by_alias ,
304
+ by_alias = by_alias if by_alias is not None else False ,
302
305
exclude_unset = exclude_unset ,
303
306
exclude_defaults = exclude_defaults ,
304
307
exclude_none = exclude_none ,
@@ -313,13 +316,14 @@ def model_dump_json(
313
316
indent : int | None = None ,
314
317
include : IncEx | None = None ,
315
318
exclude : IncEx | None = None ,
316
- by_alias : bool = False ,
319
+ by_alias : bool | None = None ,
317
320
exclude_unset : bool = False ,
318
321
exclude_defaults : bool = False ,
319
322
exclude_none : bool = False ,
320
323
round_trip : bool = False ,
321
324
warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
322
325
context : dict [str , Any ] | None = None ,
326
+ fallback : Callable [[Any ], Any ] | None = None ,
323
327
serialize_as_any : bool = False ,
324
328
) -> str :
325
329
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
@@ -348,11 +352,13 @@ def model_dump_json(
348
352
raise ValueError ("context is only supported in Pydantic v2" )
349
353
if serialize_as_any != False :
350
354
raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
355
+ if fallback is not None :
356
+ raise ValueError ("fallback is only supported in Pydantic v2" )
351
357
return super ().json ( # type: ignore[reportDeprecated]
352
358
indent = indent ,
353
359
include = include ,
354
360
exclude = exclude ,
355
- by_alias = by_alias ,
361
+ by_alias = by_alias if by_alias is not None else False ,
356
362
exclude_unset = exclude_unset ,
357
363
exclude_defaults = exclude_defaults ,
358
364
exclude_none = exclude_none ,
0 commit comments