Skip to content

Commit cd0c9b7

Browse files
committed
Merge pull request #3074 from tomchristie/unsaved_file_objects_serialize_to_none
Unsaved file objects may not have an associated URL.
2 parents 9b8f966 + 3211332 commit cd0c9b7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

rest_framework/fields.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,12 @@ def to_internal_value(self, data):
11981198
return data
11991199

12001200
def to_representation(self, value):
1201+
if not value:
1202+
return None
1203+
12011204
if self.use_url:
1202-
if not value:
1205+
if not getattr(value, 'url', None):
1206+
# If the file has not been saved it may not have a URL.
12031207
return None
12041208
url = value.url
12051209
request = self.context.get('request', None)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy