From 88047e59ba12479ef9adcaf3dee61b48566ce6eb Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Tue, 18 Jan 2011 23:22:37 +0200 Subject: [PATCH] Fix an error when a set-returning function fails halfway through the execution MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the function using yield to return rows fails halfway, the iterator stays open and subsequent calls to the function will resume reading from it. The fix is to unref the iterator and set it to NULL if there has been an error. Jan UrbaƄski --- src/pl/plpython/plpython.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pl/plpython/plpython.c b/src/pl/plpython/plpython.c index c25db9344f6..6f31501c7a8 100644 --- a/src/pl/plpython/plpython.c +++ b/src/pl/plpython/plpython.c @@ -1164,6 +1164,14 @@ PLy_function_handler(FunctionCallInfo fcinfo, PLyProcedure *proc) Py_XDECREF(plargs); Py_XDECREF(plrv); + /* + * If there was an error the iterator might have not been exhausted + * yet. Set it to NULL so the next invocation of the function will + * start the iteration again. + */ + Py_XDECREF(proc->setof); + proc->setof = NULL; + PG_RE_THROW(); } PG_END_TRY();