Skip to content

Commit 88e973d

Browse files
committed
check unexpecte val
1 parent 98fe512 commit 88e973d

File tree

1 file changed

+16
-4
lines changed
  • src/serializers/type_serializers

1 file changed

+16
-4
lines changed

src/serializers/type_serializers/union.rs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,21 @@ impl TypeSerializer for UnionSerializer {
112112
for comb_serializer in &self.choices {
113113
match comb_serializer.json_key(key, &new_extra) {
114114
Ok(v) => return Ok(v),
115-
Err(err) => extra.warnings.custom_warning(err.to_string()),
115+
Err(err) => match err.is_instance_of::<PydanticSerializationUnexpectedValue>(key.py()) {
116+
true => (),
117+
false => extra.warnings.custom_warning(err.to_string()),
118+
},
116119
}
117120
}
118121
if self.retry_with_lax_check() {
119122
new_extra.check = SerCheck::Lax;
120123
for comb_serializer in &self.choices {
121124
match comb_serializer.json_key(key, &new_extra) {
122125
Ok(v) => return Ok(v),
123-
Err(err) => extra.warnings.custom_warning(err.to_string()),
126+
Err(err) => match err.is_instance_of::<PydanticSerializationUnexpectedValue>(key.py()) {
127+
true => (),
128+
false => extra.warnings.custom_warning(err.to_string()),
129+
},
124130
}
125131
}
126132
}
@@ -144,15 +150,21 @@ impl TypeSerializer for UnionSerializer {
144150
for comb_serializer in &self.choices {
145151
match comb_serializer.to_python(value, include, exclude, &new_extra) {
146152
Ok(v) => return infer_serialize(v.bind(py), serializer, None, None, extra),
147-
Err(err) => extra.warnings.custom_warning(err.to_string()),
153+
Err(err) => match err.is_instance_of::<PydanticSerializationUnexpectedValue>(value.py()) {
154+
true => (),
155+
false => extra.warnings.custom_warning(err.to_string()),
156+
},
148157
}
149158
}
150159
if self.retry_with_lax_check() {
151160
new_extra.check = SerCheck::Lax;
152161
for comb_serializer in &self.choices {
153162
match comb_serializer.to_python(value, include, exclude, &new_extra) {
154163
Ok(v) => return infer_serialize(v.bind(py), serializer, None, None, extra),
155-
Err(err) => extra.warnings.custom_warning(err.to_string()),
164+
Err(err) => match err.is_instance_of::<PydanticSerializationUnexpectedValue>(value.py()) {
165+
true => (),
166+
false => extra.warnings.custom_warning(err.to_string()),
167+
},
156168
}
157169
}
158170
}

0 commit comments

Comments
 (0)