Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be350ed

Browse files
committed
Fixed a NameError. This potentially closes issue 5.
1 parent 63bf4a2 commit be350ed

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

django_tables/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def _default_render(self, boundcol):
7070
# also ``_validate_column_name``, where such a mechanism is
7171
# already implemented).
7272
if not hasattr(current, bit):
73-
raise ValueError("Could not resolve %s from %s" % (bit, name))
73+
raise ValueError("Could not resolve %s from %s" % (bit, boundcol.accessor))
7474

7575
current = getattr(current, bit)
7676
if callable(current):

tests/test_models.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,18 @@ class CountryTable(tables.ModelTable):
154154
test_country_table(countries)
155155

156156

157+
def test_invalid_accessor():
158+
"""Test that a column being backed by a non-existent model property
159+
is handled correctly.
160+
161+
Regression-Test: There used to be a NameError here.
162+
"""
163+
class CountryTable(tables.ModelTable):
164+
name = tables.Column(data='something-i-made-up')
165+
countries = CountryTable(Country)
166+
assert_raises(ValueError, countries[0].__getitem__, 'name')
167+
168+
157169
def test_caches():
158170
"""Make sure the caches work for model tables as well (parts are
159171
reimplemented).
@@ -259,6 +271,7 @@ class Meta:
259271
assert [row['example_domain'] for row in countries] == \
260272
[row['null'] for row in countries]
261273

274+
262275
def test_relationships():
263276
"""Test relationship spanning."""
264277

0 commit comments

Comments
 (0)