From be350ede0fa2de7b326a59f76d9f2b9449685f86 Mon Sep 17 00:00:00 2001 From: Michael Elsdoerfer Date: Wed, 25 Aug 2010 00:46:11 +0200 Subject: [PATCH] Fixed a NameError. This potentially closes issue 5. --- django_tables/models.py | 2 +- tests/test_models.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/django_tables/models.py b/django_tables/models.py index 882d42c..17fd40e 100644 --- a/django_tables/models.py +++ b/django_tables/models.py @@ -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): diff --git a/tests/test_models.py b/tests/test_models.py index c8973d6..867ba30 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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.""" -- 2.26.2