summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/build/changelog/changelog_11.rst6
-rw-r--r--lib/sqlalchemy/ext/indexable.py2
-rw-r--r--test/ext/test_indexable.py6
3 files changed, 11 insertions, 3 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index 09a63a703..8ed600639 100644
--- a/doc/build/changelog/changelog_11.rst
+++ b/doc/build/changelog/changelog_11.rst
@@ -21,6 +21,12 @@
.. changelog::
:version: 1.1.0b3
+ .. change::
+ :tags: bug, ext
+
+ sqlalchemy.ext.indexable will intercept IndexError as well
+ as KeyError when raising as AttributeError.
+
.. changelog::
:version: 1.1.0b2
:released: July 1, 2016
diff --git a/lib/sqlalchemy/ext/indexable.py b/lib/sqlalchemy/ext/indexable.py
index 5002e9beb..7d6348524 100644
--- a/lib/sqlalchemy/ext/indexable.py
+++ b/lib/sqlalchemy/ext/indexable.py
@@ -284,7 +284,7 @@ class index_property(hybrid_property): # noqa
raise AttributeError(self.attr_name)
try:
value = column_value[self.index]
- except KeyError:
+ except (KeyError, IndexError):
raise AttributeError(self.attr_name)
else:
return value
diff --git a/test/ext/test_indexable.py b/test/ext/test_indexable.py
index c8346e4c3..56f2e1786 100644
--- a/test/ext/test_indexable.py
+++ b/test/ext/test_indexable.py
@@ -23,9 +23,11 @@ class IndexPropertyTest(fixtures.TestBase):
array = Column('_array', ARRAY(Integer),
default=[])
first = index_property('array', 0)
+ tenth = index_property('array', 9)
a = A(array=[1, 2, 3])
eq_(a.first, 1)
+ assert_raises(AttributeError, lambda: a.tenth)
a.first = 100
eq_(a.first, 100)
eq_(a.array, [100, 2, 3])
@@ -89,7 +91,7 @@ class IndexPropertyTest(fixtures.TestBase):
assert_raises(AttributeError, delattr, a, "first")
- def test_get_index_error(self):
+ def test_get_attribute_error(self):
Base = declarative_base()
class A(Base):
@@ -99,7 +101,7 @@ class IndexPropertyTest(fixtures.TestBase):
first = index_property('array', 1)
a = A(array=[])
- assert_raises(IndexError, lambda: a.first)
+ assert_raises(AttributeError, lambda: a.first)
def test_set_immutable(self):
Base = declarative_base()