Sunday, December 30, 2012

Re: loaddata deserializationerror: maximum recursion depth exceeded while calling a Python object

Thanks for your suggestions.

I eliminated the underscores and got rid of the __unicode__ methods entirely, cleaned up my except statement, and changed the order of stuff such that all of each model's fields are defined before any methods. (As for the pk field: The csvs I'm using are actually dumps from another database, so everything has its own primary key already, and I realized it's way easier to just leave them alone rather than waste the processing time and memory reconnecting everything via Python.) 

I'm still having the same problem. I don't think it's related to the length of the files or something in simplejson, as even a dozen-line yaml file gives me the same exception when I try to load it with loaddata. 

Any more ideas?

On Sun, Dec 30, 2012 at 12:18 PM, Amirouche <amirouche.boubekki@gmail.com> wrote:


On Saturday, December 29, 2012 9:42:50 PM UTC+1, Sam Raker wrote:
Here's the truncated version I tried to load in case the problem was the length of the file:
- fields: {location: ST. DENNIS HOTEL, restaurant: Veterans American Guard, status: complete,
    year: 1900}
  model: dishes.menu
  pk: 12495
- fields: {location: BOSTON, restaurant: New England Shorthand Reporter's Association,
    status: complete, year: 1900}
  model: dishes.menu
  pk: 12563
- fields: {location: RMS LUCANIA, restaurant: Cunard Line, status: under review, year: 1900}
  model: dishes.menu
  pk: 12749
- fields: {location: IROQUOIS, restaurant: Alumni Association   University Of Buffalo,
    status: complete, year: 1900}
  model: dishes.menu
  pk: 12826
- fields: {location: '[CHICAGO', restaurant: Chicago Bar Association, status: complete,
    year: 1900}
  model: dishes.menu
  pk: 12836
- fields: {location: NEW YORK, restaurant: Hotel Marlborough, status: under review,
    year: 1900}
  model: dishes.menu
  pk: 12841
- fields: {location: NEW YORK, restaurant: Hotel Marlborough, status: complete, year: 1900}
  model: dishes.menu
  pk: 12960
- fields: {location: HOTEL MARLBOROUGH, restaurant: District No.3 Catholic Benevolent
      Legion, status: under review, year: 1900}
  model: dishes.menu
  pk: 13076
- fields: {location: 9 & 10 BATTERY PL. NY, restaurant: Castle Garden Hotel, status: complete,
    year: 1900}
  model: dishes.menu
  pk: 13117

Here's the model:
class Menu(models.Model):
restaurant=models.TextField(unique=False)
year=models.IntegerField(unique=False,null=True)
location=models.TextField(unique=False)
status=models.CharField(unique=False,max_length=20)
pk=models.IntegerField(primary_key=True)
def __unicode__(self):
return restaurant
try:
p=int(10*round(float(self.year)/10))
if p < self.year:
return "%s-%s"%(p,p+5)
else:
return "%s-%s"%(p-5,p)
except:
return ""
period=property(__period__)
language = models.CharField(unique=False,max_length=30)


Some recommandations:

- I never defined __XYZ__ except to look elite ;)
- how «return restaurant» in __unicode__ can possibly work ?
- unique default value = False, no need to repeat it if is not something else
- according to Django codings standards you should not inter-mix model fields with plain properties or methods
- pk=models.IntegerField(primary_key=True) What is it useful for ?
- according to pep8 «except:» should never be used instead use the «except MyException» or «except MyException, e» this prevents bugs [2]
I've got a very tight deadline, and I'm encountering a very frustrating problem. Every time I try to use loaddata to load my data into my database, I get the loaddata error in the subject. I've tried YAML, I've tried JSON, I've tried excerpting only a few lines of each, all to no avail. I'm really at my rope's end. I don't think my models are flawed in any significant way--each refers to only one field in one other model (the primary key in four out of five of them).
How big is the json file ? Which library do you use ? If you use simplejson it's probably that see: https://github.com/simplejson/simplejson/issues/28 This relates to a hierarchical data structure where your datastructure at least the one you pasted is not, I already had troubles with big JSON files and simplejson, I have no metrics sorry.

Can you use SQL ? Maybe you will need to consider spliting the json file into several file.

Regards,

Amirouche

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/FCFXKNxtvAIJ.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment