File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -608,10 +608,13 @@ def __init__(self, **kwargs):
608
608
super (BooleanField , self ).__init__ (** kwargs )
609
609
610
610
def to_internal_value (self , data ):
611
- if data in self .TRUE_VALUES :
612
- return True
613
- elif data in self .FALSE_VALUES :
614
- return False
611
+ try :
612
+ if data in self .TRUE_VALUES :
613
+ return True
614
+ elif data in self .FALSE_VALUES :
615
+ return False
616
+ except TypeError : # Input is an unhashable type
617
+ pass
615
618
self .fail ('invalid' , input = data )
616
619
617
620
def to_representation (self , value ):
Original file line number Diff line number Diff line change @@ -466,6 +466,18 @@ class TestBooleanField(FieldValues):
466
466
}
467
467
field = serializers .BooleanField ()
468
468
469
+ def test_disallow_unhashable_collection_types (self ):
470
+ inputs = (
471
+ [],
472
+ {},
473
+ )
474
+ field = serializers .BooleanField ()
475
+ for input_value in inputs :
476
+ with pytest .raises (serializers .ValidationError ) as exc_info :
477
+ field .run_validation (input_value )
478
+ expected = ['"{0}" is not a valid boolean.' .format (input_value )]
479
+ assert exc_info .value .detail == expected
480
+
469
481
470
482
class TestNullBooleanField (FieldValues ):
471
483
"""
You can’t perform that action at this time.
0 commit comments