[Django] #29325: Django docs Polls App, Diferent queryset returns same object values but QuestionIndexViewTests works for one query and fails for other

5 views
Skip to first unread message

Django

unread,
Apr 13, 2018, 5:45:56 PM4/13/18
to django-...@googlegroups.com
#29325: Django docs Polls App,Diferent queryset returns same object values but
QuestionIndexViewTests works for one query and fails for other
-------------------------------------+-------------------------------------
Reporter: hgamit | Owner: nobody
Type: Bug | Status: new
Component: Generic | Version: 2.0
views |
Severity: Normal | Keywords: polls, model, tests
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
In polls application I added annotation to check one to many relationship
between Question and Choice models such that, Index only return questions
with more than one choices to be displayed but my testcase fails all the
time with annotation where both query returns same data.

views.py (Not Working: Added annotate(num =
Count('choice')).filter(num__gt=1))

class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'

def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.annotate(num =
Count('choice')).filter(num__gt=1).filter(pub___lte=timezone.now()).order_by('-pub_date')[:5]

Error:

Traceback (most recent call last): File
"C:\Users\hmnsh\repos\DjangoApp\mysite\polls\tests.py", line 80, in
test_past_question [''] File "C:\ProgramData\Anaconda3\envs\django\lib
\site-packages\django\test\testcases.py", line 940, in assertQuerysetEqual
return self.assertEqual(list(items), values, msg=msg) AssertionError:
Lists differ: [] != ['']

--
Ticket URL: <https://code.djangoproject.com/ticket/29325>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 13, 2018, 8:19:55 PM4/13/18
to django-...@googlegroups.com
#29325: Django docs Polls App,Diferent queryset returns same object values but
QuestionIndexViewTests works for one query and fails for other
-------------------------------------+-------------------------------------
Reporter: hgamit | Owner: nobody
Type: Bug | Status: closed
Component: Generic views | Version: 2.0
Severity: Normal | Resolution: invalid

Keywords: polls, model, tests | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* status: new => closed
* resolution: => invalid


Old description:

> In polls application I added annotation to check one to many relationship
> between Question and Choice models such that, Index only return questions
> with more than one choices to be displayed but my testcase fails all the
> time with annotation where both query returns same data.
>
> views.py (Not Working: Added annotate(num =
> Count('choice')).filter(num__gt=1))
>
> class IndexView(generic.ListView):
> template_name = 'polls/index.html'
> context_object_name = 'latest_question_list'
>
> def get_queryset(self):
> """Return the last five published questions."""
> return Question.objects.annotate(num =
> Count('choice')).filter(num__gt=1).filter(pub___lte=timezone.now()).order_by('-pub_date')[:5]
>
> Error:
>
> Traceback (most recent call last): File
> "C:\Users\hmnsh\repos\DjangoApp\mysite\polls\tests.py", line 80, in
> test_past_question [''] File "C:\ProgramData\Anaconda3\envs\django\lib
> \site-packages\django\test\testcases.py", line 940, in
> assertQuerysetEqual return self.assertEqual(list(items), values, msg=msg)
> AssertionError: Lists differ: [] != ['']

New description:

In polls application I added annotation to check one to many relationship
between Question and Choice models such that, Index only return questions
with more than one choices to be displayed but my testcase fails all the
time with annotation where both query returns same data.

views.py (Not Working: Added `annotate(num =
Count('choice')).filter(num__gt=1))`
{{{
class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'

def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.annotate(num =
Count('choice')).filter(num__gt=1).filter(pub___lte=timezone.now()).order_by('-pub_date')[:5]
}}}
Error:
{{{
Traceback (most recent call last): File
"C:\Users\hmnsh\repos\DjangoApp\mysite\polls\tests.py", line 80, in
test_past_question ['']
File "C:\ProgramData\Anaconda3\envs\django\lib\site-
packages\django\test\testcases.py", line 940, in assertQuerysetEqual
return self.assertEqual(list(items), values, msg=msg) AssertionError:
Lists differ: [] != ['']
}}}

--

Comment:

Please see TicketClosingReasons/UseSupportChannels for ways to get help.

--
Ticket URL: <https://code.djangoproject.com/ticket/29325#comment:1>

Django

unread,
Apr 13, 2018, 8:49:08 PM4/13/18
to django-...@googlegroups.com
#29325: Django docs Polls App,Diferent queryset returns same object values but
QuestionIndexViewTests works for one query and fails for other
-------------------------------------+-------------------------------------
Reporter: hgamit | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 2.0
Severity: Normal | Resolution:
Keywords: polls, model, tests | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by hgamit):

* cc: hgamit (added)
* status: closed => new
* resolution: invalid =>


Comment:

@Tim Graham: I am really stuck around testcases and queryset. What is the
solution for this issue? What do you mean by invalid? Do you need more
info?

--
Ticket URL: <https://code.djangoproject.com/ticket/29325#comment:2>

Django

unread,
Apr 13, 2018, 9:35:08 PM4/13/18
to django-...@googlegroups.com
#29325: Django docs Polls App,Diferent queryset returns same object values but
QuestionIndexViewTests works for one query and fails for other
-------------------------------------+-------------------------------------
Reporter: hgamit | Owner: nobody
Type: Bug | Status: closed

Component: Generic views | Version: 2.0
Severity: Normal | Resolution: invalid

Keywords: polls, model, tests | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* status: new => closed
* resolution: => invalid


Comment:

Hello hgamit,

This ticket tracker should be used to keep track of Django bugs and
feature requests and isn't a support channel per se.

The link Tim pointed you to contains reference to mailing lists and IRC
channels where you should be able to find support for your issue.

--
Ticket URL: <https://code.djangoproject.com/ticket/29325#comment:3>

Reply all
Reply to author
Forward
0 new messages