Django

Code

Ticket #10006 (closed: fixed)

Opened 1 year ago

Last modified 1 year ago

r9707 breaks dumpdata if you have python-json installed on a Debian based system and python2.4

Reported by: markmuetz Assigned to: mtredinnick
Milestone: Component: Serialization
Version: SVN Keywords:
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

On a Debian system with python2.4, if you've got the package python-json installed, then running ./manage.py dumpdata raises an error: AttributeError: 'module' object has no attribute 'JSONEncoder'. This only happens if you're using r9707 or newer though. A workaround is to remove python-json.

I see a similar error on Ubuntu (with python2.5). If you've got python-json and don't have python-simplejson installed, then you see the same error in the same conditions. Either removing python-json or installing python-simplejson fixes it in this case.

I think this is due to older versions of python having more than one type of json lib. When the line from django.utils import simplejson is run, it goes to django/utils/simplejson/init.py which tries to use system versions of the json libs, and falls back on the one bundled with django. The old json package/module (python-json) doesn't have the right methods, so it raises an AttributeError. A simple fix is to test for JSONEncoder in the imported module, which is what the patch does.

Attachments

jsondecoder.patch (0.6 kB) - added by markmuetz on 01/10/09 15:29:36.
Patch to fix problem with older versions of python json libs

Change History

01/10/09 15:29:36 changed by markmuetz

  • attachment jsondecoder.patch added.

Patch to fix problem with older versions of python json libs

01/22/09 19:17:43 changed by bartek

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Running Ubuntu Intrepid Ibex with Python 2.5 here and simply installing python-simplejson did not fix this issue.

I had to remove python-json and use python-simplejson.

The only problem with this fix is there are some applications that are dependent on python-json (e.g deluge-torrent) and were removed so it's not an optimal solution.

HOWEVER, the patch did fix the issue.

01/22/09 19:29:29 changed by mtredinnick

  • owner changed from nobody to mtredinnick.
  • status changed from new to assigned.

Aah .. there's a third-party package out there called "json". :-(

People really shouldn't use generic names for their packages like that. It shows a simple lack of imagination (not to mention consideration).

The patch looks like the right sort of fix. Thanks for working that out.

02/03/09 15:57:37 changed by Davide "Design" Muzzarelli <reg@dav-muz.net>

Patch tested: run well on my Ubuntu 7.10 with python-json and python-simpolejson packages installed, it was necessary on my system. Django-r9811.

02/26/09 15:22:06 changed by Alex

  • stage changed from Unreviewed to Accepted.

02/26/09 23:19:21 changed by mtredinnick

  • status changed from assigned to closed.
  • resolution set to fixed.

Fixed in r9910.


Add/Change #10006 (r9707 breaks dumpdata if you have python-json installed on a Debian based system and python2.4)




Change Properties
Action