File tree Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Expand file tree Collapse file tree 3 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -393,7 +393,7 @@ def _map_serializer(self, serializer):
393
393
schema ['writeOnly' ] = True
394
394
if field .allow_null :
395
395
schema ['nullable' ] = True
396
- if field .default and field .default != empty : # why don't they use None?!
396
+ if field .default and field .default != empty and not callable ( field . default ) : # why don't they use None?!
397
397
schema ['default' ] = field .default
398
398
if field .help_text :
399
399
schema ['description' ] = str (field .help_text )
Original file line number Diff line number Diff line change @@ -571,6 +571,22 @@ def test_serializer_hstorefield(self):
571
571
properties = response_schema ['items' ]['properties' ]
572
572
assert properties ['hstore' ]['type' ] == 'object'
573
573
574
+ def test_serializer_callable_default (self ):
575
+ path = '/'
576
+ method = 'GET'
577
+ view = create_view (
578
+ views .ExampleGenericAPIView ,
579
+ method ,
580
+ create_request (path ),
581
+ )
582
+ inspector = AutoSchema ()
583
+ inspector .view = view
584
+
585
+ responses = inspector ._get_responses (path , method )
586
+ response_schema = responses ['200' ]['content' ]['application/json' ]['schema' ]
587
+ properties = response_schema ['items' ]['properties' ]
588
+ assert 'default' not in properties ['uuid_field' ]
589
+
574
590
def test_serializer_validators (self ):
575
591
path = '/'
576
592
method = 'GET'
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ class ExampleSerializer(serializers.Serializer):
58
58
date = serializers .DateField ()
59
59
datetime = serializers .DateTimeField ()
60
60
hstore = serializers .HStoreField ()
61
+ uuid_field = serializers .UUIDField (default = uuid .uuid4 )
61
62
62
63
63
64
class ExampleGenericAPIView (generics .GenericAPIView ):
You can’t perform that action at this time.
0 commit comments