@@ -257,32 +257,41 @@ def model_dump(
257257 mode : Literal ["json" , "python" ] | str = "python" ,
258258 include : IncEx | None = None ,
259259 exclude : IncEx | None = None ,
260+ context : Any | None = None ,
260261 by_alias : bool | None = None ,
261262 exclude_unset : bool = False ,
262263 exclude_defaults : bool = False ,
263264 exclude_none : bool = False ,
265+ exclude_computed_fields : bool = False ,
264266 round_trip : bool = False ,
265267 warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
266- context : dict [str , Any ] | None = None ,
267- serialize_as_any : bool = False ,
268268 fallback : Callable [[Any ], Any ] | None = None ,
269+ serialize_as_any : bool = False ,
269270 ) -> dict [str , Any ]:
270271 """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
271272
272273 Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
273274
274275 Args:
275276 mode: The mode in which `to_python` should run.
276- If mode is 'json', the dictionary will only contain JSON serializable types.
277- If mode is 'python', the dictionary may contain any Python objects.
278- include: A list of fields to include in the output.
279- exclude: A list of fields to exclude from the output.
277+ If mode is 'json', the output will only contain JSON serializable types.
278+ If mode is 'python', the output may contain non-JSON-serializable Python objects.
279+ include: A set of fields to include in the output.
280+ exclude: A set of fields to exclude from the output.
281+ context: Additional context to pass to the serializer.
280282 by_alias: Whether to use the field's alias in the dictionary key if defined.
281- exclude_unset: Whether to exclude fields that are unset or None from the output.
282- exclude_defaults: Whether to exclude fields that are set to their default value from the output.
283- exclude_none: Whether to exclude fields that have a value of `None` from the output.
284- round_trip: Whether to enable serialization and deserialization round-trip support.
285- warnings: Whether to log warnings when invalid fields are encountered.
283+ exclude_unset: Whether to exclude fields that have not been explicitly set.
284+ exclude_defaults: Whether to exclude fields that are set to their default value.
285+ exclude_none: Whether to exclude fields that have a value of `None`.
286+ exclude_computed_fields: Whether to exclude computed fields.
287+ While this can be useful for round-tripping, it is usually recommended to use the dedicated
288+ `round_trip` parameter instead.
289+ round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
290+ warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
291+ "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
292+ fallback: A function to call when an unknown value is encountered. If not provided,
293+ a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
294+ serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
286295
287296 Returns:
288297 A dictionary representation of the model.
@@ -299,6 +308,8 @@ def model_dump(
299308 raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
300309 if fallback is not None :
301310 raise ValueError ("fallback is only supported in Pydantic v2" )
311+ if exclude_computed_fields != False :
312+ raise ValueError ("exclude_computed_fields is only supported in Pydantic v2" )
302313 dumped = super ().dict ( # pyright: ignore[reportDeprecated]
303314 include = include ,
304315 exclude = exclude ,
@@ -315,15 +326,17 @@ def model_dump_json(
315326 self ,
316327 * ,
317328 indent : int | None = None ,
329+ ensure_ascii : bool = False ,
318330 include : IncEx | None = None ,
319331 exclude : IncEx | None = None ,
332+ context : Any | None = None ,
320333 by_alias : bool | None = None ,
321334 exclude_unset : bool = False ,
322335 exclude_defaults : bool = False ,
323336 exclude_none : bool = False ,
337+ exclude_computed_fields : bool = False ,
324338 round_trip : bool = False ,
325339 warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
326- context : dict [str , Any ] | None = None ,
327340 fallback : Callable [[Any ], Any ] | None = None ,
328341 serialize_as_any : bool = False ,
329342 ) -> str :
@@ -355,6 +368,10 @@ def model_dump_json(
355368 raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
356369 if fallback is not None :
357370 raise ValueError ("fallback is only supported in Pydantic v2" )
371+ if ensure_ascii != False :
372+ raise ValueError ("ensure_ascii is only supported in Pydantic v2" )
373+ if exclude_computed_fields != False :
374+ raise ValueError ("exclude_computed_fields is only supported in Pydantic v2" )
358375 return super ().json ( # type: ignore[reportDeprecated]
359376 indent = indent ,
360377 include = include ,
0 commit comments