Skip to content

Specify value in UserWarning "serialized value may not be as expected" #1336

@franklinvp

Description

@franklinvp

Would it be possible to make this warning more specific by mentioning either the value or perhaps the field that caused it?

I am calling request.model_dump_json(indent=2) and getting

UserWarning: Pydantic serializer warnings: Expected `enum` but got `str` - serialized value may not be as expected return self.__pydantic_serializer__.to_json( 

but there so many enum.Enum in the request that is hard to find which is causing the warning.

The place where the warning message is composed seems1 to know the value.

fn fallback_warning(&self, field_type: &str, value: &Bound<'_, PyAny>) { if self.mode != WarningsMode::None { let type_name = value .get_type() .qualname() .unwrap_or_else(|_| "<unknown python object>".to_owned()); self.add_warning(format!( "Expected `{field_type}` but got `{type_name}` - serialized value may not be as expected" )); } }

Footnotes

  1. I am not sure, since I am not familiar with Rust.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions