Fixed a NameError. This potentially closes issue 5.
authorMichael Elsdoerfer <michael@elsdoerfer.com>
Tue, 24 Aug 2010 22:46:11 +0000 (00:46 +0200)
committerMichael Elsdoerfer <michael@elsdoerfer.com>
Tue, 24 Aug 2010 22:46:11 +0000 (00:46 +0200)
django_tables/models.py
tests/test_models.py

index 882d42c304d3ce3bafe28acb4aa609a9dfd932ca..17fd40e9210fe16c6d8066dd8425bb1785afa33a 100644 (file)
@@ -70,7 +70,7 @@ class BoundModelRow(BoundRow):
             # also ``_validate_column_name``, where such a mechanism is
             # already implemented).
             if not hasattr(current, bit):
-                raise ValueError("Could not resolve %s from %s" % (bit, name))
+                raise ValueError("Could not resolve %s from %s" % (bit, boundcol.accessor))
 
             current = getattr(current, bit)
             if callable(current):
index c8973d636cec3b0b2fb46b90e9978557e107f812..867ba30d18c4eb7aeccd730cc4e1c7747e6d44de 100644 (file)
@@ -154,6 +154,18 @@ def test_basic():
     test_country_table(countries)
 
 
+def test_invalid_accessor():
+    """Test that a column being backed by a non-existent model property
+    is handled correctly.
+
+    Regression-Test: There used to be a NameError here.
+    """
+    class CountryTable(tables.ModelTable):
+        name = tables.Column(data='something-i-made-up')
+    countries = CountryTable(Country)
+    assert_raises(ValueError, countries[0].__getitem__, 'name')
+
+
 def test_caches():
     """Make sure the caches work for model tables as well (parts are
     reimplemented).
@@ -259,6 +271,7 @@ def test_callable():
     assert [row['example_domain'] for row in countries] == \
                     [row['null'] for row in countries]
 
+
 def test_relationships():
     """Test relationship spanning."""