File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -442,10 +442,10 @@ def get_attribute(self, instance):
442
442
except (KeyError , AttributeError ) as exc :
443
443
if self .default is not empty :
444
444
return self .get_default ()
445
- if self .allow_null :
446
- return None
447
445
if not self .required :
448
446
raise SkipField ()
447
+ if self .allow_null :
448
+ return None
449
449
msg = (
450
450
'Got {exc_type} when attempting to get a value for field '
451
451
'`{field}` on serializer `{serializer}`.\n The serializer '
Original file line number Diff line number Diff line change @@ -372,6 +372,14 @@ def create(self, validated_data):
372
372
serializer .save ()
373
373
assert serializer .data == {'included' : 'abc' }
374
374
375
+ def test_not_required_output_for_allow_null_field (self ):
376
+ class ExampleSerializer (serializers .Serializer ):
377
+ omitted = serializers .CharField (required = False , allow_null = True )
378
+ included = serializers .CharField ()
379
+
380
+ serializer = ExampleSerializer ({'included' : 'abc' })
381
+ assert 'omitted' not in serializer .data
382
+
375
383
376
384
class TestDefaultOutput :
377
385
def setup (self ):
You can’t perform that action at this time.
0 commit comments