django-simple-rest icon indicating copy to clipboard operation
django-simple-rest copied to clipboard

JSON serialization does not work with Django 1.5 and simplejson

Open espenak opened this issue 12 years ago • 0 comments

Seems to work fine without simplejson, but today I had to add another package that has a hard dependency on simplejson, so now django-simple-rest stopped working. The trackeback is:

Traceback (most recent call last):
  File "/.../Django-1.5.1-py2.7.egg/django/core/handlers/base.py", line 115, in get_response
    response = callback(request, *callback_args, **callback_kwargs)
  File "/.../Django-1.5.1-py2.7.egg/django/views/generic/base.py", line 68, in view
    return self.dispatch(request, *args, **kwargs)
  File "/.../Django-1.5.1-py2.7.egg/django/views/decorators/csrf.py", line 77, in wrapped_view
    return view_func(*args, **kwargs)
  File "/.../django_simple_rest-1.4.1-py2.7.egg/simple_rest/resource.py", line 44, in dispatch
    response = super(Resource, self).dispatch(request, *args, **kwargs)
  File "/.../Django-1.5.1-py2.7.egg/django/views/generic/base.py", line 86, in dispatch
    return handler(request, *args, **kwargs)
  File "/.../Django-1.5.1-py2.7.egg/django/utils/decorators.py", line 25, in _wrapper
    return bound_func(*args, **kwargs)
  File "/.../django_simple_rest-1.4.1-py2.7.egg/simple_rest/response.py", line 99, in wrapper
    response = self.render_to_response(request, data, status_code, kwargs.get('_format', None))
  File "/.../django_simple_rest-1.4.1-py2.7.egg/simple_rest/response.py", line 121, in render_to_response
    response = HttpResponse(templ_or_func(data))
  File "/.../django_simple_rest-1.4.1-py2.7.egg/simple_rest/utils/serializers.py", line 37, in to_json
    serialized_content = json.dumps(content, cls=DjangoJSONEncoder, ensure_ascii=False, indent=indent)
  File "/.../simplejson-2.6.2-py2.7-macosx-10.8-intel.egg/simplejson/__init__.py", line 334, in dumps
    **kw).encode(obj)
TypeError: __init__() got an unexpected keyword argument 'namedtuple_as_object'

The fix in 8b56e347e1b53b91b05c2033f5c87b7a5c33db3f works, but it seems a bit inefficient/hacky, and it is not in the latest release (1.4.1).

Have you done any performance analytics on the simplejson version shipped with newerish python versions vs. simplejson? The reason I ask is that I am wondering if simplejson is worth the extra complexity/hacks, or if it might be better to follow Django 1.5, and simply use the built-in json-module?

Thanks for creating this brilliant peace of software.

espenak avatar Nov 06 '13 21:11 espenak