@@ -281,14 +281,15 @@ def model_dump(
281
281
mode : Literal ["json" , "python" ] | str = "python" ,
282
282
include : IncEx | None = None ,
283
283
exclude : IncEx | None = None ,
284
- by_alias : bool = False ,
284
+ by_alias : bool | None = None ,
285
285
exclude_unset : bool = False ,
286
286
exclude_defaults : bool = False ,
287
287
exclude_none : bool = False ,
288
288
round_trip : bool = False ,
289
289
warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
290
290
context : dict [str , Any ] | None = None ,
291
291
serialize_as_any : bool = False ,
292
+ fallback : Callable [[Any ], Any ] | None = None ,
292
293
) -> dict [str , Any ]:
293
294
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
294
295
@@ -320,10 +321,12 @@ def model_dump(
320
321
raise ValueError ("context is only supported in Pydantic v2" )
321
322
if serialize_as_any != False :
322
323
raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
324
+ if fallback is not None :
325
+ raise ValueError ("fallback is only supported in Pydantic v2" )
323
326
dumped = super ().dict ( # pyright: ignore[reportDeprecated]
324
327
include = include ,
325
328
exclude = exclude ,
326
- by_alias = by_alias ,
329
+ by_alias = by_alias if by_alias is not None else False ,
327
330
exclude_unset = exclude_unset ,
328
331
exclude_defaults = exclude_defaults ,
329
332
exclude_none = exclude_none ,
@@ -338,13 +341,14 @@ def model_dump_json(
338
341
indent : int | None = None ,
339
342
include : IncEx | None = None ,
340
343
exclude : IncEx | None = None ,
341
- by_alias : bool = False ,
344
+ by_alias : bool | None = None ,
342
345
exclude_unset : bool = False ,
343
346
exclude_defaults : bool = False ,
344
347
exclude_none : bool = False ,
345
348
round_trip : bool = False ,
346
349
warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
347
350
context : dict [str , Any ] | None = None ,
351
+ fallback : Callable [[Any ], Any ] | None = None ,
348
352
serialize_as_any : bool = False ,
349
353
) -> str :
350
354
"""Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump_json
@@ -373,11 +377,13 @@ def model_dump_json(
373
377
raise ValueError ("context is only supported in Pydantic v2" )
374
378
if serialize_as_any != False :
375
379
raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
380
+ if fallback is not None :
381
+ raise ValueError ("fallback is only supported in Pydantic v2" )
376
382
return super ().json ( # type: ignore[reportDeprecated]
377
383
indent = indent ,
378
384
include = include ,
379
385
exclude = exclude ,
380
- by_alias = by_alias ,
386
+ by_alias = by_alias if by_alias is not None else False ,
381
387
exclude_unset = exclude_unset ,
382
388
exclude_defaults = exclude_defaults ,
383
389
exclude_none = exclude_none ,
0 commit comments