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):
393393 schema ['writeOnly' ] = True
394394 if field .allow_null :
395395 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?!
397397 schema ['default' ] = field .default
398398 if field .help_text :
399399 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):
571571 properties = response_schema ['items' ]['properties' ]
572572 assert properties ['hstore' ]['type' ] == 'object'
573573
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+
574590 def test_serializer_validators (self ):
575591 path = '/'
576592 method = 'GET'
Original file line number Diff line number Diff line change @@ -58,6 +58,7 @@ class ExampleSerializer(serializers.Serializer):
5858 date = serializers .DateField ()
5959 datetime = serializers .DateTimeField ()
6060 hstore = serializers .HStoreField ()
61+ uuid_field = serializers .UUIDField (default = uuid .uuid4 )
6162
6263
6364class ExampleGenericAPIView (generics .GenericAPIView ):
You can’t perform that action at this time.
0 commit comments