@@ -78,13 +78,14 @@ impl TypeSerializer for UnionSerializer {
78
78
// try the serializers in left to right order with error_on fallback=true
79
79
let mut new_extra = extra. clone ( ) ;
80
80
new_extra. check = SerCheck :: Strict ;
81
+ let mut errors: Vec < PyErr > = Vec :: new ( ) ;
81
82
82
83
for comb_serializer in & self . choices {
83
84
match comb_serializer. to_python ( value, include, exclude, & new_extra) {
84
85
Ok ( v) => return Ok ( v) ,
85
86
Err ( err) => match err. is_instance_of :: < PydanticSerializationUnexpectedValue > ( value. py ( ) ) {
86
87
true => ( ) ,
87
- false => extra . warnings . custom_warning ( err. to_string ( ) ) ,
88
+ false => errors . push ( err) ,
88
89
} ,
89
90
}
90
91
}
@@ -95,25 +96,31 @@ impl TypeSerializer for UnionSerializer {
95
96
Ok ( v) => return Ok ( v) ,
96
97
Err ( err) => match err. is_instance_of :: < PydanticSerializationUnexpectedValue > ( value. py ( ) ) {
97
98
true => ( ) ,
98
- false => extra . warnings . custom_warning ( err. to_string ( ) ) ,
99
+ false => errors . push ( err) ,
99
100
} ,
100
101
}
101
102
}
102
103
}
103
104
105
+ for err in & errors {
106
+ extra. warnings . custom_warning ( err. to_string ( ) ) ;
107
+ }
108
+
104
109
extra. warnings . on_fallback_py ( self . get_name ( ) , value, extra) ?;
105
110
infer_to_python ( value, include, exclude, extra)
106
111
}
107
112
108
113
fn json_key < ' a > ( & self , key : & ' a Bound < ' _ , PyAny > , extra : & Extra ) -> PyResult < Cow < ' a , str > > {
109
114
let mut new_extra = extra. clone ( ) ;
110
115
new_extra. check = SerCheck :: Strict ;
116
+ let mut errors: Vec < PyErr > = Vec :: new ( ) ;
117
+
111
118
for comb_serializer in & self . choices {
112
119
match comb_serializer. json_key ( key, & new_extra) {
113
120
Ok ( v) => return Ok ( v) ,
114
121
Err ( err) => match err. is_instance_of :: < PydanticSerializationUnexpectedValue > ( key. py ( ) ) {
115
122
true => ( ) ,
116
- false => extra . warnings . custom_warning ( err. to_string ( ) ) ,
123
+ false => errors . push ( err) ,
117
124
} ,
118
125
}
119
126
}
@@ -124,12 +131,16 @@ impl TypeSerializer for UnionSerializer {
124
131
Ok ( v) => return Ok ( v) ,
125
132
Err ( err) => match err. is_instance_of :: < PydanticSerializationUnexpectedValue > ( key. py ( ) ) {
126
133
true => ( ) ,
127
- false => extra . warnings . custom_warning ( err. to_string ( ) ) ,
134
+ false => errors . push ( err) ,
128
135
} ,
129
136
}
130
137
}
131
138
}
132
139
140
+ for err in & errors {
141
+ extra. warnings . custom_warning ( err. to_string ( ) ) ;
142
+ }
143
+
133
144
extra. warnings . on_fallback_py ( self . get_name ( ) , key, extra) ?;
134
145
infer_json_key ( key, extra)
135
146
}
@@ -145,13 +156,14 @@ impl TypeSerializer for UnionSerializer {
145
156
let py = value. py ( ) ;
146
157
let mut new_extra = extra. clone ( ) ;
147
158
new_extra. check = SerCheck :: Strict ;
159
+ let mut errors: Vec < PyErr > = Vec :: new ( ) ;
148
160
149
161
for comb_serializer in & self . choices {
150
162
match comb_serializer. to_python ( value, include, exclude, & new_extra) {
151
163
Ok ( v) => return infer_serialize ( v. bind ( py) , serializer, None , None , extra) ,
152
164
Err ( err) => match err. is_instance_of :: < PydanticSerializationUnexpectedValue > ( value. py ( ) ) {
153
165
true => ( ) ,
154
- false => extra . warnings . custom_warning ( err. to_string ( ) ) ,
166
+ false => errors . push ( err) ,
155
167
} ,
156
168
}
157
169
}
@@ -162,12 +174,16 @@ impl TypeSerializer for UnionSerializer {
162
174
Ok ( v) => return infer_serialize ( v. bind ( py) , serializer, None , None , extra) ,
163
175
Err ( err) => match err. is_instance_of :: < PydanticSerializationUnexpectedValue > ( value. py ( ) ) {
164
176
true => ( ) ,
165
- false => extra . warnings . custom_warning ( err. to_string ( ) ) ,
177
+ false => errors . push ( err) ,
166
178
} ,
167
179
}
168
180
}
169
181
}
170
182
183
+ for err in & errors {
184
+ extra. warnings . custom_warning ( err. to_string ( ) ) ;
185
+ }
186
+
171
187
extra. warnings . on_fallback_ser :: < S > ( self . get_name ( ) , value, extra) ?;
172
188
infer_serialize ( value, serializer, include, exclude, extra)
173
189
}
0 commit comments