Issue 59 in django-jython: CursorWrapper in zxjdbc/postgresql/base.py needs __iter__ method to support raw queries

18 views
Skip to first unread message

django...@googlecode.com

unread,
Mar 22, 2011, 5:22:53 PM3/22/11
to django-j...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 59 by dbres...@gmail.com: CursorWrapper in
zxjdbc/postgresql/base.py needs __iter__ method to support raw queries
http://code.google.com/p/django-jython/issues/detail?id=59

What steps will reproduce the problem?
1. In settings.py, use the following database engine:
'ENGINE': 'doj.backends.zxjdbc.postgresql'

2. Try to iterate over a table in the database (here, "snapshot") using a
raw query:
for s in Snapshot.objects.raw('SELECT * FROM snapshot'):
print s.name


What is the expected output? What do you see instead?

Instead of seeing the 'name' column for each of the rows, an exception is
thrown:

Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\soft\jython2.5.2\Lib\site-packages\django\db\models\query.py",
line 1406, in __iter__
query = iter(self.query)

File "C:\soft\jython2.5.2\Lib\site-packages\django\db\models\sql\query.py",
line 80, in __iter__
return iter(result)
File "C:\soft\jython2.5.2\Lib\site-packages\django\db\backends\util.py",
line 42, in __iter__
return iter(self.cursor)
TypeError: 'CursorWrapper' object is not iterable


What version of the product are you using? On what operating system?
django-jython-1.2.0b1 on Windows XP

Please provide any additional information below.

Here's the __iter__ method that we added to CursorWrapper in
doj/backends/zxjdbc/postgresql/base.py :

def __iter__(self):
i = self.next()
while i:
yield i
i = self.next()

With this method, iterating over the RawQuerySet that's returned from a
RawQuery works as expected.

django...@googlecode.com

unread,
Mar 22, 2011, 9:45:38 PM3/22/11
to django-j...@googlegroups.com
Updates:
Status: Accepted
Owner: juneau001

Comment #1 on issue 59 by juneau001: CursorWrapper in

zxjdbc/postgresql/base.py needs __iter__ method to support raw queries
http://code.google.com/p/django-jython/issues/detail?id=59

Thanks for the feedback and the code to repair this issue. I will test and
roll this fix in for the next release.

django...@googlecode.com

unread,
Jun 15, 2011, 9:06:15 AM6/15/11
to django-j...@googlegroups.com

Comment #2 on issue 59 by kbrow...@gmail.com: CursorWrapper in
zxjdbc/postgresql/base.py needs __iter__ method to support raw queries
http://code.google.com/p/django-jython/issues/detail?id=59

Will this be added any time soon? Seems like an easy fix that's low risk
due to it only effecting raw queries, which without this fix are broken.

django...@googlecode.com

unread,
Oct 24, 2011, 1:10:17 PM10/24/11
to django-j...@googlegroups.com

Comment #3 on issue 59 by mrjohns...@gmail.com: CursorWrapper in
zxjdbc/postgresql/base.py needs __iter__ method to support raw queries
http://code.google.com/p/django-jython/issues/detail?id=59

Here's a patch that should work for all backends.

diff -r 87f0d585b19b doj/backends/zxjdbc/common.py
--- a/doj/backends/zxjdbc/common.py Tue May 31 07:45:46 2011 -0500
+++ b/doj/backends/zxjdbc/common.py Mon Oct 24 10:08:12 2011 -0700
@@ -111,6 +111,10 @@
def __getattr__(self, attr):
return getattr(self.cursor, attr)

+ def __iter__(self):
+ return iter(self.next, None)
+
+
# Must be called by zxJDBC backends after instantiating a connection
def set_default_isolation_level(connection, innodb_binlog = False):
jdbc_conn = connection.__connection__


django...@googlecode.com

unread,
Oct 24, 2011, 1:14:22 PM10/24/11
to django-j...@googlegroups.com
Updates:
Status: Started

Comment #4 on issue 59 by juneau001: CursorWrapper in

zxjdbc/postgresql/base.py needs __iter__ method to support raw queries
http://code.google.com/p/django-jython/issues/detail?id=59

Great! Thanks for the patch. Will start testing today.

django...@googlecode.com

unread,
Aug 10, 2014, 4:20:29 AM8/10/14
to django-j...@googlegroups.com
Updates:
Status: Fixed

Comment #5 on issue 59 by andr...@st0cker.at: CursorWrapper in
zxjdbc/postgresql/base.py needs __iter__ method to support raw queries
http://code.google.com/p/django-jython/issues/detail?id=59

(No comment was entered for this change.)

--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
Reply all
Reply to author
Forward
0 new messages