@@ -263,32 +263,41 @@ def model_dump(
263263 mode : Literal ["json" , "python" ] | str = "python" ,
264264 include : IncEx | None = None ,
265265 exclude : IncEx | None = None ,
266+ context : Any | None = None ,
266267 by_alias : bool | None = None ,
267268 exclude_unset : bool = False ,
268269 exclude_defaults : bool = False ,
269270 exclude_none : bool = False ,
271+ exclude_computed_fields : bool = False ,
270272 round_trip : bool = False ,
271273 warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
272- context : dict [str , Any ] | None = None ,
273- serialize_as_any : bool = False ,
274274 fallback : Callable [[Any ], Any ] | None = None ,
275+ serialize_as_any : bool = False ,
275276 ) -> dict [str , Any ]:
276277 """Usage docs: https://docs.pydantic.dev/2.4/concepts/serialization/#modelmodel_dump
277278
278279 Generate a dictionary representation of the model, optionally specifying which fields to include or exclude.
279280
280281 Args:
281282 mode: The mode in which `to_python` should run.
282- If mode is 'json', the dictionary will only contain JSON serializable types.
283- If mode is 'python', the dictionary may contain any Python objects.
284- include: A list of fields to include in the output.
285- exclude: A list of fields to exclude from the output.
283+ If mode is 'json', the output will only contain JSON serializable types.
284+ If mode is 'python', the output may contain non-JSON-serializable Python objects.
285+ include: A set of fields to include in the output.
286+ exclude: A set of fields to exclude from the output.
287+ context: Additional context to pass to the serializer.
286288 by_alias: Whether to use the field's alias in the dictionary key if defined.
287- exclude_unset: Whether to exclude fields that are unset or None from the output.
288- exclude_defaults: Whether to exclude fields that are set to their default value from the output.
289- exclude_none: Whether to exclude fields that have a value of `None` from the output.
290- round_trip: Whether to enable serialization and deserialization round-trip support.
291- warnings: Whether to log warnings when invalid fields are encountered.
289+ exclude_unset: Whether to exclude fields that have not been explicitly set.
290+ exclude_defaults: Whether to exclude fields that are set to their default value.
291+ exclude_none: Whether to exclude fields that have a value of `None`.
292+ exclude_computed_fields: Whether to exclude computed fields.
293+ While this can be useful for round-tripping, it is usually recommended to use the dedicated
294+ `round_trip` parameter instead.
295+ round_trip: If True, dumped values should be valid as input for non-idempotent types such as Json[T].
296+ warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
297+ "error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
298+ fallback: A function to call when an unknown value is encountered. If not provided,
299+ a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError] error is raised.
300+ serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
292301
293302 Returns:
294303 A dictionary representation of the model.
@@ -305,6 +314,8 @@ def model_dump(
305314 raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
306315 if fallback is not None :
307316 raise ValueError ("fallback is only supported in Pydantic v2" )
317+ if exclude_computed_fields != False :
318+ raise ValueError ("exclude_computed_fields is only supported in Pydantic v2" )
308319 dumped = super ().dict ( # pyright: ignore[reportDeprecated]
309320 include = include ,
310321 exclude = exclude ,
@@ -321,15 +332,17 @@ def model_dump_json(
321332 self ,
322333 * ,
323334 indent : int | None = None ,
335+ ensure_ascii : bool = False ,
324336 include : IncEx | None = None ,
325337 exclude : IncEx | None = None ,
338+ context : Any | None = None ,
326339 by_alias : bool | None = None ,
327340 exclude_unset : bool = False ,
328341 exclude_defaults : bool = False ,
329342 exclude_none : bool = False ,
343+ exclude_computed_fields : bool = False ,
330344 round_trip : bool = False ,
331345 warnings : bool | Literal ["none" , "warn" , "error" ] = True ,
332- context : dict [str , Any ] | None = None ,
333346 fallback : Callable [[Any ], Any ] | None = None ,
334347 serialize_as_any : bool = False ,
335348 ) -> str :
@@ -361,6 +374,10 @@ def model_dump_json(
361374 raise ValueError ("serialize_as_any is only supported in Pydantic v2" )
362375 if fallback is not None :
363376 raise ValueError ("fallback is only supported in Pydantic v2" )
377+ if ensure_ascii != False :
378+ raise ValueError ("ensure_ascii is only supported in Pydantic v2" )
379+ if exclude_computed_fields != False :
380+ raise ValueError ("exclude_computed_fields is only supported in Pydantic v2" )
364381 return super ().json ( # type: ignore[reportDeprecated]
365382 indent = indent ,
366383 include = include ,
0 commit comments