diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index a78df34..1fce4d4 100644
a
|
b
|
class Query(object):
|
1666 | 1666 | except MultiJoin: |
1667 | 1667 | raise FieldError("Invalid field name: '%s'" % name) |
1668 | 1668 | except FieldError: |
1669 | | names = opts.get_all_field_names() + self.extra.keys() + self.aggregate_select.keys() |
1670 | | names.sort() |
1671 | | raise FieldError("Cannot resolve keyword %r into field. " |
1672 | | "Choices are: %s" % (name, ", ".join(names))) |
| 1669 | if name.find(LOOKUP_SEP) != -1: |
| 1670 | # For lookups spanning over relationships, show the choices |
| 1671 | # from the model on which the lookup failed |
| 1672 | raise |
| 1673 | else: |
| 1674 | names = opts.get_all_field_names() + self.extra.keys() + self.aggregate_select.keys() |
| 1675 | names.sort() |
| 1676 | raise FieldError("Cannot resolve keyword %r into field. " |
| 1677 | "Choices are: %s" % (name, ", ".join(names))) |
1673 | 1678 | self.remove_inherited_models() |
1674 | 1679 | |
1675 | 1680 | def add_ordering(self, *ordering): |
diff --git a/tests/modeltests/many_to_one/tests.py b/tests/modeltests/many_to_one/tests.py
index bc9fe64..2081c48 100644
a
|
b
|
from __future__ import absolute_import, with_statement
|
3 | 3 | from copy import deepcopy |
4 | 4 | from datetime import datetime |
5 | 5 | |
6 | | from django.core.exceptions import MultipleObjectsReturned |
| 6 | from django.core.exceptions import MultipleObjectsReturned, FieldError |
7 | 7 | from django.test import TestCase |
8 | 8 | |
9 | 9 | from .models import Article, Reporter |
… |
… |
class ManyToOneTests(TestCase):
|
412 | 412 | |
413 | 413 | # Same as each other |
414 | 414 | self.assertTrue(r1.article_set.__class__ is r2.article_set.__class__) |
| 415 | |
| 416 | def test_values_list_exception(self): |
| 417 | expected_message = "Cannot resolve keyword 'notafield' into field. Choices are: %s" |
| 418 | |
| 419 | self.assertRaisesMessage(FieldError, |
| 420 | expected_message % ', '.join(Reporter._meta.get_all_field_names()), |
| 421 | Article.objects.values_list, |
| 422 | 'reporter__notafield') |
| 423 | self.assertRaisesMessage(FieldError, |
| 424 | expected_message % ', '.join(['EXTRA',] + Article._meta.get_all_field_names()), |
| 425 | Article.objects.extra(select={'EXTRA': 'EXTRA_SELECT'}).values_list, |
| 426 | 'notafield') |