Django dev JSONEncoder is now based on json #535

Closed
wants to merge 1 commit into
from

Projects

None yet

5 participants

@maraujop
Contributor

Djando dev breaks Tastypie serialization. Tastypie uses Django json.JSONEncoder, which was based on simplejson in previous versions, but it's now based on json, which doesn't accept a keyword argument
namedtuple_as_object anymore.

This raises this runtime error:

__init__() got an unexpected keyword argument 'namedtuple_as_object'

So in Django 1.5 we need to pass JSONEncoder to json, instead of simplejson.

See my comments on the commit in Django that introduced this change:
django/django@cec6bd5#django-core-serializers-json-py-P46

I'm not sure if this should be fixed in Django or Tastypie, meanwhile we can have Tastypie working with latest Django dev version with this patch.

Cheers,
Miguel

@maraujop maraujop Django dev JSONSerializer is now based on json
Djando dev breaks Tastypie serialization. Tastypie uses Django
`json.JSONEncoder`, which was based on simplejson in previous versions,
but it's now based on json, which doesn't accept a keyword argument
`namedtuple_as_object` anymore.

So in Django 1.5 we need to pass `JSONEncoder` to json, instead of
simplejson
16c94c1
@maraujop
Contributor

I found more about this at django-dev discussion list:
https://groups.google.com/forum/?fromgroups#!topic/django-developers/JM4ndZbk_wY

@joshbohde
Contributor

I spent some time on getting tests running against master of Django, and did not get this error. Is this still an issue?

@maraujop
Contributor

I just tried reverting this commit from our fork of django-tastypie and running our API test suite against it with latest Django master, and 92% tests fail.

So unless I'm doing something wrong (I've double checked everything) this is still an issue.

Cheers,
Miguel

@ivasic
ivasic commented Sep 7, 2012

I can confirm I'm also experiencing the same problem.
However, it's odd that it all works good on osx with python 2.7.2 while it fails on linux with python 2.7.3 (not sure if it's related or some other kind of weirdness is present...)

@wilonth
wilonth commented Sep 22, 2012

The cause is: on linux the package python-simplejson is installed as a dependency of other packages, which contains newer versions (>2) of simplejson, and these versions are not compatible with the json package shipped with python2.7.
To solve it:

  1. Just to make sure, first uninstall the current version of simplejson in the python dir (pip uninstall simplejson)
    Note that we don't uninstall the python-simplejson package of the distro.
  2. Install an old version of simplejson, 1.9.3 works (easy_install simplejson==1.9.3)
    The old version will take over and allow us to run tastypie happily with django 1.5, at least on my machine.
@ivasic
ivasic commented Sep 22, 2012

I'm using the patch from @maraujop right now and it works okay. It seems to me like a better solution for now, but thanks!

@wilonth
wilonth commented Sep 22, 2012

I'm wondering why this patch hasn't got merged into master, it helps prevent any potential problems related to this issue, it only modifies several lines of code and it's nothing but good T_T.
Actually, my solution works but it sucks.

@toastdriven
Contributor

@phaikawl It hasn't been merged because I haven't had time to test it myself with 1.5. But since I'm sick to death of everyone grumping about everything tonight, it's merged as of SHA: fd18c23.

Does it work? I dunno. Good luck.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment