﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
13834	Dumpdata/loaddata cycle fails when using a single-field natural key	Claude Paroz	nobody	"Here is a sample model:
{{{
from django.db import models

class OntologyManager(models.Manager):
    def get_by_natural_key(self, name):
        return self.get(name=name)

class Ontology(models.Model):
    name        = models.CharField(max_length=32, unique=True)

    objects = OntologyManager()

    def natural_key(self):
        return self.name

class Term(models.Model):
    name        = models.CharField(max_length=255)
    ontology    = models.ForeignKey(Ontology)
}}}

Then create an ontology and a term linked to this ontology. Then run:
{{{
python manage.py dumpdata --natural --indent=1 > testdata.json
python manage.py loaddata testdata.json
}}}
And the result:
{{{
Problem installing fixture 'testdata.json': Traceback (most recent call last):
  File ""/usr/local/lib/python2.6/dist-packages/django/core/management/commands/loaddata.py"", line 165, in handle
    for obj in objects:
  File ""/usr/local/lib/python2.6/dist-packages/django/core/serializers/json.py"", line 38, in Deserializer
    for obj in PythonDeserializer(simplejson.load(stream), **options):
  File ""/usr/local/lib/python2.6/dist-packages/django/core/serializers/python.py"", line 119, in Deserializer
    value = field.rel.to._meta.get_field(field.rel.field_name).to_python(field_value)
  File ""/usr/local/lib/python2.6/dist-packages/django/db/models/fields/__init__.py"", line 468, in to_python
    raise exceptions.ValidationError(self.error_messages['invalid'])
ValidationError: [u'This value must be an integer.']
}}}

The bug is probably around the {{{if hasattr(field_value, '__iter__'):}}} line in django/core/serializers/python.py (Deserializer function). If I manually add brackets around the Ontology name in the JSON file, the loaddata command succeeds."		closed	Core (Serialization)	1.2		invalid			Unreviewed	0	0	0	0	0	0
