Opened 10 years ago

Closed 10 years ago

#23654 closed Uncategorized (invalid)

test_index_view_with_two_past_questions() raising ValueError

Reported by: skalrynd Owned by: nobody
Component: Documentation Version: 1.7
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

While following tutorial 5 and executing the test at: https://docs.djangoproject.com/en/1.7/intro/tutorial05/

I got a raised exception:

Traceback (most recent call last):
  File "/var/www/project.com/project/polls/tests.py", line 97, in test_index_view_with_two_past_questions
    ['<Question: Past question 2.>', '<Question: Past question 1.>']
  File "/usr/local/lib/python3.4/dist-packages/django/test/testcases.py", line 853, in assertQuerysetEqual
    raise ValueError("Trying to compare non-ordered queryset "
ValueError: Trying to compare non-ordered queryset against more than one ordered values

I found the error to be resolved using list():

def test_index_view_with_two_past_questions(self):
        """
        The questions index page may display multiple questions.
        """
        create_question(question_text="Past question 1.", days=-30)
        create_question(question_text="Past question 2.", days=-5)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            list(response.context['latest_question_list']),
            list(['<Question: Past question 2.>', '<Question: Past question 1.>'])
        )

Change History (2)

comment:1 by Baptiste Mispelon, 10 years ago

Hi,

Are you using the same view as the one defined in part 4 [1]?

Those define the queryset as Question.objects.order_by('-pub_date')[:5] so that error message should not get triggered.

Thanks.

[1] https://docs.djangoproject.com/en/1.7/intro/tutorial04/#amend-views

comment:2 by skalrynd, 10 years ago

Resolution: invalid
Status: newclosed

That resolved it.

Note: See TracTickets for help on using tickets.
Back to Top