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 11[bumpversion]
2- current_version = 0.33 .0
2+ current_version = 0.34 .0
33
44[bumpversion:file:pyproject.toml]
55
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
66
77# [ Unreleased]
88
9+ # [ 0.34.0]
10+ - [ PR 178] ( https://github.com/salesforce/django-declarative-apis/pull/178 ) Fix JSONEmitter for empty response bodies.
11+
912# [ 0.33.0]
1013- [ PR 170] ( https://github.com/salesforce/django-declarative-apis/pull/170 ) Update publish workflow
1114- [ 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):
182182
183183 def render (self , request ):
184184 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 ""
192191
193192 # Callback
194193 # TODO: do we care about JSONP?
195194 # if cb and is_valid_jsonp_callback_value(cb):
196195 # return '%s(%s)' % (cb, seria)
197196
198- return seria
197+ return json .dumps (
198+ seria ,
199+ cls = DjangoJSONEncoder ,
200+ ensure_ascii = False ,
201+ indent = 4 ,
202+ )
199203
200204
201205Emitter .register ("json" , JSONEmitter , "application/json; charset=utf-8" )
Original file line number Diff line number Diff line change 7575# built documents.
7676
7777# The full version, including alpha/beta/rc tags.
78- release = "0.33 .0" # set by bumpversion
78+ release = "0.34 .0" # set by bumpversion
7979
8080# The short X.Y version.
8181version = release .rsplit ("." , 1 )[0 ]
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44
55[project ]
66name = " django-declarative-apis"
7- version = " 0.33 .0" # set by bumpversion
7+ version = " 0.34 .0" # set by bumpversion
88description = " Simple, readable, declarative APIs for Django"
99readme = " README.md"
1010dependencies = [
Original file line number Diff line number Diff line change @@ -109,6 +109,15 @@ def test_decode(self):
109109 resp = em .render (django .test .RequestFactory ().get ("/" ))
110110 self .assertEqual (json .loads (resp ), ["foo" , "bar" ])
111111
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+
112121
113122class DjangoEmitterTestCase (unittest .TestCase ):
114123 def test_render_http_response_succes (self ):
You can’t perform that action at this time.
0 commit comments