Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Attribute Error on Dumpdata

8 views
Skip to first unread message

ttk

unread,
Dec 6, 2007, 7:10:33 PM12/6/07
to Django users
Hello all,

I'm getting an attribute error when I try running the dumpdata command
on any of my apps.

news = app name
NewsEntry = model

Output:
=========
C:\someproject>manage.py dumpdata news
Traceback (most recent call last):
File "C:\someproject\manage.py", line 11, in <module>
execute_manager(settings)
File "C:\Python25\lib\site-packages\django\core\management
\__init__.py", line 277, in execute_manager
utility.execute()
File "C:\Python25\lib\site-packages\django\core\management
\__init__.py", line 225, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Python25\lib\site-packages\django\core\management\base.py",
line 70, in run_from_argv
self.execute(*args, **options.__dict__)
File "C:\Python25\lib\site-packages\django\core\management\base.py",
line 84, in execute
output = self.handle(*args, **options)
File "C:\Python25\lib\site-packages\django\core\management\commands
\dumpdata.py", line 37, in handle
objects.extend(model.objects.all())
AttributeError: type object 'NewsEntry' has no attribute 'objects'
==============

I suspect this is related somehow my models setup. However, after
searching, I couldn't find any one with a similar issue.

Model class:
========
from django.db import models
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.contrib.sites.managers import CurrentSiteManager

class NewsEntry(models.Model):

site = models.ForeignKey(Site)
on_site = CurrentSiteManager()
...
===========
So I use, for example: NewsEntry.on_site.all() INSTEAD OF
NewsEntry.objects.all()

This is all based off of the Django "Sites Framework" documentation
(http://snipr.com/1uvnz).

Any insight would be appreciated.

Thanks much in advance,
ttk

ttk

unread,
Dec 6, 2007, 8:01:53 PM12/6/07
to Django users
I think I found my problem...

I failed to add "objects = models.Manager()" into my models which
would explain why that attribute isn't found.

I'll try this out but if anyone has additional suggestions, I'm all
ears.

cheers,
-ttk

Karen Tracey

unread,
Dec 7, 2007, 12:03:31 PM12/7/07
to django...@googlegroups.com
Seems dumpdata is coded to require a Manager named 'objects' for the Models it dumps, even though (as described here: http://www.djangoproject.com/documentation/model-api/#manager-names), Django does not require that a Manager named objects exists for all Models.  Whether this is just an oversight in dumpdata or a conscious decision I  can't say, though it looks like an oversight to me.

Karen

Empty

unread,
Dec 7, 2007, 2:31:08 PM12/7/07
to django...@googlegroups.com
> Seems dumpdata is coded to require a Manager named 'objects' for the Models
> it dumps, even though (as described here:
> http://www.djangoproject.com/documentation/model-api/#manager-names), Django
> does not require that a Manager named objects exists for all Models.
> Whether this is just an oversight in dumpdata or a conscious decision I
> can't say, though it looks like an oversight to me.

You're correct Karen. This bit of code is the culprit:

objects = []
for app in app_list:
for model in get_models(app):
objects.extend(model.objects.all())

How would you propose that it be done differently? I know that
through object._meta.admin.manager will give you the first manager
like the Admin works off of, but that is only populated if the Admin
inner class is defined. I looked for the logic that does that but I
couldn't find it.

Michael Trier
blog.michaeltrier.com

Karen Tracey

unread,
Dec 7, 2007, 3:15:25 PM12/7/07
to django...@googlegroups.com

I believe it should be using _default_manager, which looks to be set to track the first Manager defined for a Model.  I think a (legitimate) Model will always have _default_manager, while it may not always have objects.

Karen

Empty

unread,
Dec 7, 2007, 5:48:38 PM12/7/07
to django...@googlegroups.com
Added ticket http://code.djangoproject.com/ticket/6155 with patch.
Still need to write tests.

Michael

Reply all
Reply to author
Forward
0 new messages