Exceptions raised by the columns iterator propagated.

This commit is contained in:
Daniele Varrazzo 2010-07-10 00:12:50 +01:00
parent cb8128c6d4
commit deb2d9050f
3 changed files with 22 additions and 0 deletions

View File

@ -7,6 +7,9 @@
projects using logging but where no handler is installed on the root
logger. Bug reported by Joe Abbate.
* psycopg/cursor_type.c: exceptions raised in the columns iterator of the
copy methods propagated to the caller.
2010-05-20 Daniele Varrazzo <daniele.varrazzo@gmail.com>
* psycopg/typecast_datetime.c: Round seconds in historical timezones to

View File

@ -1151,6 +1151,11 @@ static int _psyco_curs_copy_columns(PyObject *columns, char *columnlist)
}
Py_DECREF(coliter);
/* Error raised by the coliter generator */
if (PyErr_Occurred()) {
return -1;
}
if (offset == 2) {
return 0;
}

View File

@ -71,6 +71,20 @@ class CopyTests(unittest.TestCase):
curs.execute("select * from tcopy order by id")
self.assertEqual([(i, None) for i in range(10)], curs.fetchall())
def test_copy_from_cols_err(self):
curs = self.conn.cursor()
f = StringIO()
for i in xrange(10):
f.write("%s\n" % (i,))
f.seek(0)
def cols():
raise ZeroDivisionError()
yield 'id'
self.assertRaises(ZeroDivisionError,
curs.copy_from, MinimalRead(f), "tcopy", columns=cols())
def test_copy_to(self):
curs = self.conn.cursor()
try: