summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/cextension
diff options
context:
space:
mode:
authorLele Gaifax <lele@metapensiero.it>2016-01-28 09:04:40 +0100
committerLele Gaifax <lele@metapensiero.it>2016-01-28 09:04:40 +0100
commitf84ef1f83cc64a5ea3a910b8d1bdf00b05e9ceab (patch)
tree88ea72eea39fd076dc730a304a9ec9823dfb6aa3 /lib/sqlalchemy/cextension
parent086ad9ce6413e73f93506523d4eb8e23710443dc (diff)
downloadsqlalchemy-pr/231.tar.gz
- properly handle negative indexes in RowProxy.__getitem__()pr/231
Diffstat (limited to 'lib/sqlalchemy/cextension')
-rw-r--r--lib/sqlalchemy/cextension/resultproxy.c4
1 files changed, 4 insertions, 0 deletions
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)