What steps will reproduce the problem?
list(SomeModel.objects.raw("SELECT * FROM SomeModelTable"))
Crashes -- "'CursorWrapper' object is not iterable" with a backtrace ending
with:
File "C:\Python26\lib\site-packages\django\db\models\query.py" in __iter__
1248. for row in self.query:
File "C:\Python26\lib\site-packages\django\db\models\sql\query.py" in
__iter__
58. return iter(self.cursor)
django-pyodbc revision 175
django 1.2 alpha 1 SVN-12224
windows 2003, sql server 2000
I was able to "fix" the problem by providing the iterator in
sql_server.pyodbc.base.CursorWrapper:
def __iter__(self):
class MyIterator(object):
def __init__(self, wrapper):
self.rows = wrapper.fetchall()
self.ix = 0
def __iter__(self):
return self
def next(self):
if self.ix == len(self.rows):
raise StopIteration
else:
self.ix += 1
return self.rows[self.ix - 1]
return MyIterator(self)
I'm sure this is a terrible solution, but it works, and maybe will help
coming up with a proper solution.
Original issue reported on code.google.com by ama...@gmail.com on 22 Jan 2010 at 3:38
Original issue reported on code.google.com by
ama...@gmail.com
on 22 Jan 2010 at 3:38