Skip to content

Commit f1236ff

Browse files
committed
limit value_str
1 parent c325609 commit f1236ff

File tree

1 file changed

+9
-2
lines changed
  • src/serializers/type_serializers

1 file changed

+9
-2
lines changed

src/serializers/type_serializers/union.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ use std::borrow::Cow;
88
use crate::build_tools::py_schema_err;
99
use crate::common::union::{Discriminator, SMALL_UNION_THRESHOLD};
1010
use crate::definitions::DefinitionsBuilder;
11+
use crate::errors::write_truncated_to_50_bytes;
1112
use crate::lookup_key::LookupKey;
1213
use crate::serializers::type_serializers::py_err_se_err;
13-
use crate::tools::SchemaDict;
14+
use crate::tools::{safe_repr, SchemaDict};
1415
use crate::PydanticSerializationUnexpectedValue;
1516

1617
use super::{
@@ -445,9 +446,15 @@ impl TaggedUnionSerializer {
445446
Discriminator::Function(func) => func.call1(py, (value,)).ok(),
446447
};
447448
if discriminator_value.is_none() {
449+
let input_str = safe_repr(value);
450+
let mut value_str = String::with_capacity(100);
451+
value_str.push_str("with value `");
452+
write_truncated_to_50_bytes(&mut value_str, input_str.to_cow()).expect("Writing to a `String` failed");
453+
value_str.push('`');
454+
448455
extra.warnings.custom_warning(
449456
format!(
450-
"Failed to get discriminator value for tagged union serialization for {value} - defaulting to left to right union serialization."
457+
"Failed to get discriminator value for tagged union serialization {value_str} - defaulting to left to right union serialization."
451458
)
452459
);
453460
}

0 commit comments

Comments
 (0)