Skip to content

Commit

Permalink
Fix issue with JSONP of errors on streamed output.
Browse files Browse the repository at this point in the history
If a callback variable was supplied for a view that errors (e.g. no
polygons), then this led to a cacheable (200) response which contained a
generator function (iterencode) in its _closable_objects attribute. The
cache could not then pickle this attribute and so raised an exception.

This was okay in previous versions because of a side effect of the
smart_bytes workaround for Django bug #24240 that was in place; this
was removed when support for Django prior to 1.8 was dropped.

Fix the issue by using an identity map (as map has no close() method and
so is not added to _closable_objects).
  • Loading branch information
dracos committed Nov 6, 2015
1 parent e528619 commit 2a30c9e
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mapit/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def output_json(out, code=200):
encoder = GEOS_JSONEncoder(ensure_ascii=False, indent=indent)
content = encoder.iterencode(out)

# We don't want a generator function (iterencode) to be passed to an
# HttpResponse, as it won't cache due to its close() function adding it to
# an instance attribute.
content = map(lambda x: x, content)

types = {
400: http.HttpResponseBadRequest,
404: http.HttpResponseNotFound,
Expand Down

0 comments on commit 2a30c9e

Please sign in to comment.