File tree Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Expand file tree Collapse file tree 2 files changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -246,10 +246,11 @@ impl<'a> Input<'a> for PyAny {
246
246
Err ( _) => return Err ( ValError :: new ( ErrorTypeDefaults :: StringUnicode , self ) ) ,
247
247
} ;
248
248
Ok ( s. into ( ) )
249
- } else if coerce_numbers_to_str && {
249
+ } else if coerce_numbers_to_str && ! PyBool :: is_exact_type_of ( self ) && {
250
250
let py = self . py ( ) ;
251
251
let decimal_type: Py < PyType > = get_decimal_type ( py) ;
252
252
253
+ // only allow int, float, and decimal (not bool)
253
254
self . is_instance_of :: < PyInt > ( )
254
255
|| self . is_instance_of :: < PyFloat > ( )
255
256
|| self . is_instance ( decimal_type. as_ref ( py) ) . unwrap_or_default ( )
Original file line number Diff line number Diff line change @@ -277,6 +277,16 @@ def test_coerce_numbers_to_str_disabled_in_strict_mode() -> None:
277
277
v .validate_json ('42' )
278
278
279
279
280
+ def test_coerce_numbers_to_str_raises_for_bool () -> None :
281
+ config = core_schema .CoreConfig (coerce_numbers_to_str = True )
282
+
283
+ v = SchemaValidator (core_schema .str_schema (), config )
284
+ with pytest .raises (ValidationError ):
285
+ v .validate_python (True )
286
+ with pytest .raises (ValidationError ):
287
+ v .validate_json (False )
288
+
289
+
280
290
@pytest .mark .parametrize (
281
291
('number' , 'expected_str' ),
282
292
[
You can’t perform that action at this time.
0 commit comments