905: can't load siteconfig data from fixtures

akai****@gmai***** (Google Code) (Is this you? Claim this profile.)
Feb. 25, 2009
What steps will reproduce the problem?
>>> from djblets.siteconfig.models import SiteConfiguration
>>> s=SiteConfiguration(site_id=1)
>>> s.set('mykey', 'myvalue')
>>> s.save()

$ ./manage.py dumpdata siteconfig --indent=2 | tee /tmp/siteconfig.json
[
  {
    "pk": 1, 
    "model": "siteconfig.siteconfiguration", 
    "fields": {
      "version": "", 
      "site": 1, 
      "settings": "{u'mykey': u'myvalue'}"
    }
  }
]

$ ./manage.py loaddata /tmp/siteconfig.json

What is the expected output? What do you see instead?

Should load the fixture as expected. Spits the following traceback instead:

Installing json fixture '/tmp/siteconfig' from '/tmp/siteconfig'.
Problem installing fixture '/tmp/siteconfig.json': Traceback (most recent
call last):
  File "django/core/management/commands/loaddata.py", line 150, in handle
    for obj in objects:
  File "django/core/serializers/json.py", line 41, in Deserializer
    for obj in PythonDeserializer(simplejson.load(stream)):
  File "django/core/serializers/python.py", line 96, in Deserializer
    yield base.DeserializedObject(Model(**data), m2m_data)
  File "djblets/siteconfig/models.py", line 54, in __init__
    models.Model.__init__(self, *args, **kwargs)
  File "django/db/models/base.py", line 266, in __init__
    signals.post_init.send(sender=self.__class__, instance=self)
  File "django/dispatch/dispatcher.py", line 148, in send
    response = receiver(signal=self, sender=sender, **named)
  File "djblets/util/fields.py", line 159, in post_init
    value = self.loads(value)
  File "djblets/util/fields.py", line 169, in loads
    val = simplejson.loads(s, encoding=settings.DEFAULT_CHARSET)
  File "django/utils/simplejson/__init__.py", line 343, in loads
    return cls(encoding=encoding, **kw).decode(s)
  File "django/utils/simplejson/decoder.py", line 326, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "django/utils/simplejson/decoder.py", line 342, in raw_decode
    obj, end = self.scan_once(s, idx)
  File "django/utils/simplejson/scanner.py", line 36, in _scan_once
    return parse_object((string, idx + 1), encoding, strict, _scan_once,
object_hook)
  File "django/utils/simplejson/decoder.py", line 153, in JSONObject
    raise ValueError(errmsg("Expecting property name", s, end))
ValueError: Expecting property name: line 1 column 1 (char 1)

I trimmed source file paths in the traceback for clarity. Using XML as the
serialization format gives a similar traceback.

What operating system are you using? What browser?

Ubuntu Intrepid 8.10, Python 2.5.2, Django trunk @9825.
#1 akai****@gmai***** (Google Code) (Is this you? Claim this profile.)
I suspected that the problem might be that Python unicode representations instead of
double-quoted strings are present in the value of the "settings" field. I dumped in
XML and fixed them, resulting in this fixture file:

<?xml version="1.0" encoding="utf-8"?>
<django-objects version="1.0">
  <object pk="1" model="siteconfig.siteconfiguration">
    <field to="sites.site" name="site" rel="ManyToOneRel">1</field>
    <field type="CharField" name="version"></field>
    <field type="TextField" name="settings">{"mykey": "myvalue"}</field>
  </object>
</django-objects>

Now the traceback is different:

Installing xml fixture '/tmp/siteconfig' from '/tmp/siteconfig'.
Problem installing fixture '/tmp/siteconfig.xml': Traceback (most recent call last):
  File "django/core/management/commands/loaddata.py", line 153, in handle
    obj.save()
  File "django/core/serializers/base.py", line 163, in save
    models.Model.save_base(self.object, raw=True)
  File "django/db/models/base.py", line 379, in save_base
    rows = manager.filter(pk=pk_val)._update(values)
  File "django/db/models/query.py", line 468, in _update
    return query.execute_sql(None)
  File "django/db/models/sql/subqueries.py", line 119, in execute_sql
    cursor = super(UpdateQuery, self).execute_sql(result_type)
  File "django/db/models/sql/query.py", line 1974, in execute_sql
    cursor.execute(sql, params)
  File "django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
  File "django/db/backends/sqlite3/base.py", line 190, in execute
    return Database.Cursor.execute(self, query, params)
InterfaceError: Error binding parameter 2 - probably unsupported type.
chipx86
#2 chipx86
The problem is that you can't dump siteconfig data due to a bug in Django. You'll get
incorrectly serialized data that won't load back in, and we can't do anything about
this until Django is fixed.

See http://code.djangoproject.com/ticket/9522

If you apply the patch there to your install, it should work.
  • +ThirdParty