Discussion:
query.all() returns None?
d***@gmail.com
2008-05-06 15:17:36 UTC
Permalink
Hi,

I have been using SQLAlchemy with Pylons. I map a table to a class and
use ORM(reflection) to work with it. I am using MySQL for the backend.

The class is Job and the table is "jobs". I can create and insert new
Jobs but whenever I try to get any back I get "None". This used to
work just fine and it still works fine for my other mapped classes. I
did change the jobs table quite a bit, but I restarted my computer and
it still wouldnt work.

There are records in the correct table and running the SQL generated
by all()(with echo turned on) returns rows.
print Session.query(Job).all()
[None]

Any variation also fails.

Thanks for the help.
Dan

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Bayer
2008-05-06 15:25:53 UTC
Permalink
Post by d***@gmail.com
Hi,
I have been using SQLAlchemy with Pylons. I map a table to a class and
use ORM(reflection) to work with it. I am using MySQL for the backend.
The class is Job and the table is "jobs". I can create and insert new
Jobs but whenever I try to get any back I get "None". This used to
work just fine and it still works fine for my other mapped classes. I
did change the jobs table quite a bit, but I restarted my computer and
it still wouldnt work.
There are records in the correct table and running the SQL generated
by all()(with echo turned on) returns rows.
print Session.query(Job).all()
[None]
Any variation also fails.
any chance that Job defines a __repr__() method with no return value ?


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
d***@gmail.com
2008-05-06 15:42:16 UTC
Permalink
No, I do implement a __str__ so that I can format up the composite
primary key. I didnt implement __repr__ at all.

Dan
Post by Michael Bayer
Post by d***@gmail.com
Hi,
I have been using SQLAlchemy with Pylons. I map a table to a class and
use ORM(reflection) to work with it. I am using MySQL for the backend.
The class is Job and the table is "jobs". I can create and insert new
Jobs but whenever I try to get any back I get "None". This used to
work just fine and it still works fine for my other mapped classes. I
did change the jobs table quite a bit, but I restarted my computer and
it still wouldnt work.
There are records in the correct table and running the SQL generated
by all()(with echo turned on) returns rows.
print Session.query(Job).all()
[None]
Any variation also fails.
any chance that Job defines a __repr__() method with no return value ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Bayer
2008-05-06 16:00:13 UTC
Permalink
Post by d***@gmail.com
No, I do implement a __str__ so that I can format up the composite
primary key. I didnt implement __repr__ at all.
Ok you'd have to work up an example script that can illustrate this
happening, I can't see any codepath that would actually return "None"
inside a list. Id check very carefully to ensure that it is actually
[None] and not just a particular string representation of an instance.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
d***@gmail.com
2008-05-06 16:28:55 UTC
Permalink
Ok, its pretty hard to really put an example script up, but heres the
relelvant parts.

#From the Model
jobs_table = Table('jobs', metadata, autoload=True)
mapper(Job, jobs_table )

#The Job Class is pretty generic so I wont include it
#The method that does the display with a debug print
def list(self):
c.jobs = Session.query(Job).all()
for j in c.jobs:
print j
return render('/jobs/listjobs.mako')

#Error/output to console
None

#Pylons Error
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute
'jobnum'

#Interactive debugger >>> is stuff I executed
Post by d***@gmail.com
print Session.query(Job).all()
[None]
Post by d***@gmail.com
print Session.query(Job).first()
None
Post by d***@gmail.com
print Session.query(Job)
SELECT jobs.cmdline AS jobs_cmdline, jobs.nextschd AS jobs_jobnum,
jobs.repunit AS jobs_repunit, jobs.repvalue AS jobs_repvalue, etc. etc.
(there are like a million fields)
FROM jobs ORDER BY jobs.batch

The SQL generated works perfectly when run in a query tool.

The only thing I really changed was elminating a bunch of fields from
this table, then restarting everything.

Thanks,
Dan
Post by d***@gmail.com
No, I do implement a __str__ so that I can format up the composite
primary key. I didnt implement __repr__ at all.
Ok you'd have to work up an example script that can illustrate this  
happening, I can't see any codepath that would actually return "None"  
inside a list.  Id check very carefully to ensure that it is actually  
[None] and not just a particular string representation of an instance.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Bayer
2008-05-06 16:55:17 UTC
Permalink
that doesnt help much. We really need a standalone script which
reproduces the behavior on its own. You'll probably find the issue
yourself as you go through this process.
Post by d***@gmail.com
#From the Model
jobs_table = Table('jobs', metadata, autoload=True)
mapper(Job, jobs_table )
#The Job Class is pretty generic so I wont include it
#The method that does the display with a debug print
c.jobs = Session.query(Job).all()
print j
return render('/jobs/listjobs.mako')
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com
To unsubscribe from this group, send email to sqlalchemy-***@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---
Michael Bayer
2008-05-06 17:06:59 UTC
Permalink
Post by d***@gmail.com
#Interactive debugger >>> is stuff I executed
print Session.query(Job).all()
[None]
print Session.query(Job).first()
None
heres other things to try.

1. you are on SQLAlchemy 0.4.5.

2. do not use any 3rd party Python REPL tools like IPython. all kinds
of weird things seem to happen with those.

3. sess = create_session()
j = sess.query(Job).first()
assert j is not None

4. j1 = Job()
assert repr(j1) != 'None'

5. use pdb to trace through the query.all() process. methods to look
at are Query.iterate_instances(), Mapper._instance().
Mapper._instance never returns None (its not really possible).


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

Loading...