AttributeError: type object 'User' has no attribute 'query'

1,605 views
Skip to first unread message

renier

unread,
Sep 16, 2007, 1:41:37 AM9/16/07
to SQLElixir
I'm getting this with Elixir 0.4.0, Turbogears-1.0.3.2dev_r3487, and
SQLAlchemy-0.4.0beta5:
>>> u = User.get_by(user_id='per...@server.com')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/usr/lib/python2.5/site-packages/Elixir-0.4.0-py2.5.egg/elixir/
entity.py", line 641, in get_by
return cls.query().filter_by(*args, **kwargs).first()
File "/usr/lib/python2.5/site-packages/Elixir-0.4.0-py2.5.egg/elixir/
entity.py", line 601, in __getattribute__
return type.__getattribute__(cls, name)
AttributeError: type object 'User' has no attribute 'query'

'User' directly inherits from Elixir's Entity class and it follows the
User class demonstrated in the web site example.

Furthermore, I read in SA 0.3 and 0.4's documentation that the query
API is used like this:
session.query(User).filter(...)...
which does not look like the form used in Entity.get_by, nor there is
a class query method attached to handle it.

This makes me think that an addition like the following is necessary
to class Entity:

--- entity.py.orig 2007-09-10 15:19:43.000000000 -0400
+++ entity.py 2007-09-16 01:27:53.000000000 -0400
@@ -640,6 +640,10 @@
def get_by(cls, *args, **kwargs):
return cls.query().filter_by(*args, **kwargs).first()
get_by = classmethod(get_by)
+
+ def query(cls):
+ return cls.mapper.get_session().query(cls)
+ query = classmethod(query)


Is this right?

--Renier

Gaetan de Menten

unread,
Sep 21, 2007, 12:17:03 PM9/21/07
to sqle...@googlegroups.com

Sorry for the slow answer, couldn't do anything related in the past
few weeks. Depending on the version of SQLAlchemy you are using, and
how your define your session, this is correct or not. I'll try to fix
this issue for all cases in the near future. Thanks for the report, I
didn't think this case could happen until I saw your problem (which is
TurboGears related again).

--
Gaëtan de Menten
http://openhex.org

Gaetan de Menten

unread,
Sep 24, 2007, 10:04:24 AM9/24/07
to sqle...@googlegroups.com

This issue should be fixed now (as of r210). Could you try the latest
trunk and see how it goes?

Reply all
Reply to author
Forward
0 new messages