diff --git a/src/pl/plpython/plpy_elog.c b/src/pl/plpython/plpy_elog.c
index 7d3d0d49816772e9c0b2e08564504d1f8fd4e428..7495e7d51dcbf92e429c84ce3a839f43eda302e2 100644
--- a/src/pl/plpython/plpy_elog.c
+++ b/src/pl/plpython/plpy_elog.c
@@ -255,6 +255,12 @@ PLy_traceback(PyObject *e, PyObject *v, PyObject *tb,
PG_TRY();
{
+ /*
+ * Ancient versions of Python (circa 2.3) contain a bug whereby
+ * the fetches below can fail if the error indicator is set.
+ */
+ PyErr_Clear();
+
lineno = PyObject_GetAttrString(tb, "tb_lineno");
if (lineno == NULL)
elog(ERROR, "could not get line number from Python traceback");