Ticket #17497: valueslisterrormessage.diff

File valueslisterrormessage.diff, 2.6 KB (added by antoviaque, 13 years ago)
  • django/db/models/sql/query.py

    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):  
    16661666        except MultiJoin:
    16671667            raise FieldError("Invalid field name: '%s'" % name)
    16681668        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)))
    16731678        self.remove_inherited_models()
    16741679
    16751680    def add_ordering(self, *ordering):
  • tests/modeltests/many_to_one/tests.py

    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  
    33from copy import deepcopy
    44from datetime import datetime
    55
    6 from django.core.exceptions import MultipleObjectsReturned
     6from django.core.exceptions import MultipleObjectsReturned, FieldError
    77from django.test import TestCase
    88
    99from .models import Article, Reporter
    class ManyToOneTests(TestCase):  
    412412
    413413        # Same as each other
    414414        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')
Back to Top