From f84ef1f83cc64a5ea3a910b8d1bdf00b05e9ceab Mon Sep 17 00:00:00 2001 From: Lele Gaifax Date: Thu, 28 Jan 2016 09:04:40 +0100 Subject: - properly handle negative indexes in RowProxy.__getitem__() --- lib/sqlalchemy/cextension/resultproxy.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'lib/sqlalchemy/cextension') diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c index a87fe7b56..331fae2b2 100644 --- a/lib/sqlalchemy/cextension/resultproxy.c +++ b/lib/sqlalchemy/cextension/resultproxy.c @@ -263,6 +263,8 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) #if PY_MAJOR_VERSION < 3 if (PyInt_CheckExact(key)) { index = PyInt_AS_LONG(key); + if (index < 0) + index += BaseRowProxy_length(self); } else #endif @@ -271,6 +273,8 @@ BaseRowProxy_subscript(BaseRowProxy *self, PyObject *key) if ((index == -1) && PyErr_Occurred()) /* -1 can be either the actual value, or an error flag. */ return NULL; + if (index < 0) + index += BaseRowProxy_length(self); } else if (PySlice_Check(key)) { values = PyObject_GetItem(self->row, key); if (values == NULL) -- cgit v1.2.1