views:

133

answers:

1

I have a model like this:

class Group(db.Model):
  name = db.StringProperty()
  description = db.TextProperty()

Sometimes when executing queries like:

groups = Group.all().order("name").fetch(20)

or

groups = Group.all()

I'm getting error massages like this:

Traceback (most recent call last):
File "/opt/google_appengine/google/appengine/ext/webapp/__init__.py", line 501, in __call__
handler.get(*groups)
File "/home/al/Desktop/p/mwr-dev/main.py", line 638, in get
groups = Group.all()
AttributeError: type object 'Group' has no attribute 'all'

But when I'm using GQL queries with the same meaning, everything goes fine.

Why does that happens? I'm don't getting why GAE thinks that 'all' is attribute?


UPDATE: Oops ... I've found out that I also had request handler named the same as model ;(

+3  A: 

all is indeed an attribute (specifically an executable one, a method) but as Group inherits from Model it should have that attribute; clearly something strange is going on, for example the name Group at the point does not refer to the object you think it does. I suggest putting a try / except AttributeError, e: around your groups = Group.all() call, and in the except branch emit (e.g. by logging) all possible information you can find about Group, including what __bases__ it actually has, its dir(), and so forth.

This is about how far one can go in trying to help you (diagnosing that something very weird must have happened to the name Group and suggesting how to pinpoint details) without seeing your many hundreds of lines of code that could be doing who-knows-what to that name!-).

Alex Martelli