@@ -26,8 +26,12 @@ def to_internal_value(self, data):
26
26
return attribute
27
27
28
28
def to_representation (self , instance ):
29
- attribute = super ().to_representation (instance )
30
- attribute ['values' ] = attribute ['values' ].split ('\n ' )
29
+ if instance :
30
+ attribute = super ().to_representation (instance )
31
+ attribute ['values' ] = attribute ['values' ].split ('\n ' )
32
+ else :
33
+ attribute = instance
34
+
31
35
return attribute
32
36
33
37
class LabelSerializer (serializers .ModelSerializer ):
@@ -75,8 +79,11 @@ def to_internal_value(self, data):
75
79
76
80
# pylint: disable=no-self-use
77
81
def to_representation (self , instance ):
78
- upload_dir = instance .task .get_upload_dirname ()
79
- return instance .file .path [len (upload_dir ) + 1 :]
82
+ if instance :
83
+ upload_dir = instance .task .get_upload_dirname ()
84
+ return instance .file .path [len (upload_dir ) + 1 :]
85
+ else :
86
+ return instance
80
87
81
88
class ServerFileSerializer (serializers .ModelSerializer ):
82
89
class Meta :
@@ -89,7 +96,7 @@ def to_internal_value(self, data):
89
96
90
97
# pylint: disable=no-self-use
91
98
def to_representation (self , instance ):
92
- return instance .file
99
+ return instance .file if instance else instance
93
100
94
101
class RemoteFileSerializer (serializers .ModelSerializer ):
95
102
class Meta :
@@ -102,7 +109,7 @@ def to_internal_value(self, data):
102
109
103
110
# pylint: disable=no-self-use
104
111
def to_representation (self , instance ):
105
- return instance .file
112
+ return instance .file if instance else instance
106
113
107
114
class RqStatusSerializer (serializers .Serializer ):
108
115
state = serializers .ChoiceField (choices = [
0 commit comments