File tree Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Expand file tree Collapse file tree 2 files changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -259,6 +259,8 @@ def to_internal_value(self, data):
259259 data = self .pk_field .to_internal_value (data )
260260 queryset = self .get_queryset ()
261261 try :
262+ if isinstance (data , bool ):
263+ raise TypeError
262264 return queryset .get (pk = data )
263265 except ObjectDoesNotExist :
264266 self .fail ('does_not_exist' , pk_value = data )
Original file line number Diff line number Diff line change @@ -107,6 +107,12 @@ def test_pk_related_lookup_invalid_type(self):
107107 msg = excinfo .value .detail [0 ]
108108 assert msg == 'Incorrect type. Expected pk value, received BadType.'
109109
110+ def test_pk_related_lookup_bool (self ):
111+ with pytest .raises (serializers .ValidationError ) as excinfo :
112+ self .field .to_internal_value (True )
113+ msg = excinfo .value .detail [0 ]
114+ assert msg == 'Incorrect type. Expected pk value, received bool.'
115+
110116 def test_pk_representation (self ):
111117 representation = self .field .to_representation (self .instance )
112118 assert representation == self .instance .pk
You can’t perform that action at this time.
0 commit comments