File tree Expand file tree Collapse file tree 6 files changed +27
-11
lines changed
django_declarative_apis/resources Expand file tree Collapse file tree 6 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 1
1
[bumpversion]
2
- current_version = 0.33 .0
2
+ current_version = 0.34 .0
3
3
4
4
[bumpversion:file:pyproject.toml]
5
5
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
7
7
# [ Unreleased]
8
8
9
+ # [ 0.34.0]
10
+ - [ PR 178] ( https://github.com/salesforce/django-declarative-apis/pull/178 ) Fix JSONEmitter for empty response bodies.
11
+
9
12
# [ 0.33.0]
10
13
- [ PR 170] ( https://github.com/salesforce/django-declarative-apis/pull/170 ) Update publish workflow
11
14
- [ PR 173] ( https://github.com/salesforce/django-declarative-apis/pull/173 ) handle request.GET or request.POST being None + a few other improvements
Original file line number Diff line number Diff line change @@ -182,20 +182,24 @@ def decode(self, data):
182
182
183
183
def render (self , request ):
184
184
cb = request .GET .get ("callback" , None )
185
- assert cb is None , "JSONP Callbacks not suppoted"
186
- seria = json .dumps (
187
- self .decode (self .construct ()),
188
- cls = DjangoJSONEncoder ,
189
- ensure_ascii = False ,
190
- indent = 4 ,
191
- )
185
+ assert cb is None , "JSONP Callbacks not supported"
186
+ seria = self .decode (self .construct ())
187
+ if isinstance (seria , list ):
188
+ if len (seria ) == 0 or (len (seria ) == 1 and len (seria [0 ]) == 0 ):
189
+ # the body is empty, no need to run json.dumps
190
+ return ""
192
191
193
192
# Callback
194
193
# TODO: do we care about JSONP?
195
194
# if cb and is_valid_jsonp_callback_value(cb):
196
195
# return '%s(%s)' % (cb, seria)
197
196
198
- return seria
197
+ return json .dumps (
198
+ seria ,
199
+ cls = DjangoJSONEncoder ,
200
+ ensure_ascii = False ,
201
+ indent = 4 ,
202
+ )
199
203
200
204
201
205
Emitter .register ("json" , JSONEmitter , "application/json; charset=utf-8" )
Original file line number Diff line number Diff line change 75
75
# built documents.
76
76
77
77
# The full version, including alpha/beta/rc tags.
78
- release = "0.33 .0" # set by bumpversion
78
+ release = "0.34 .0" # set by bumpversion
79
79
80
80
# The short X.Y version.
81
81
version = release .rsplit ("." , 1 )[0 ]
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
5
5
[project ]
6
6
name = " django-declarative-apis"
7
- version = " 0.33 .0" # set by bumpversion
7
+ version = " 0.34 .0" # set by bumpversion
8
8
description = " Simple, readable, declarative APIs for Django"
9
9
readme = " README.md"
10
10
dependencies = [
Original file line number Diff line number Diff line change @@ -109,6 +109,15 @@ def test_decode(self):
109
109
resp = em .render (django .test .RequestFactory ().get ("/" ))
110
110
self .assertEqual (json .loads (resp ), ["foo" , "bar" ])
111
111
112
+ def test_decode_empty_list (self ):
113
+ em = emitters .JSONEmitter (["" ], lambda : None )
114
+ resp = em .render (django .test .RequestFactory ().get ("/" ))
115
+ self .assertEqual (resp , "" )
116
+
117
+ em = emitters .JSONEmitter ([], lambda : None )
118
+ resp = em .render (django .test .RequestFactory ().get ("/" ))
119
+ self .assertEqual (resp , "" )
120
+
112
121
113
122
class DjangoEmitterTestCase (unittest .TestCase ):
114
123
def test_render_http_response_succes (self ):
You can’t perform that action at this time.
0 commit comments