[Django] #28587: ListView cleaning ar

26 views
Skip to first unread message

Django

unread,
Sep 12, 2017, 4:10:18 AM9/12/17
to django-...@googlegroups.com
#28587: ListView cleaning ar
-------------------------------------+-------------------------------------
Reporter: Adrian | Owner: nobody
Type: Bug | Status: new
Component: Generic | Version: 1.11
views | Keywords: ListView, CBV,
Severity: Normal | generic,
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
When I have in my urlpatterns args and kwargs the ListView is loosing args
(it's returning empty tuple)


{{{
url(r"^(\w+)/test1/(?P<pk>[0-9]+)/list/$", SamplesListView.as_view(),
name='list_view'),
}}}

Simple code for my view:


{{{
class SamplesListView(ListView):
model = Sample
template_name = 'samples/samples_list.html'

def get(self, request, project_name, *args, **kwargs):
print("project_name", project_name)
return super().get(self, request, project_name, *args, **kwargs)
}}}


It works ok when I pass only args or kwargs into url.

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

Django

unread,
Sep 12, 2017, 4:11:33 AM9/12/17
to django-...@googlegroups.com
#28587: ListView cleaning args when you pass args and kwargs into urlpattern

-------------------------------------+-------------------------------------
Reporter: Adrian | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: ListView, CBV, | Triage Stage:
generic, | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

Django

unread,
Sep 14, 2017, 4:05:02 AM9/14/17
to django-...@googlegroups.com
#28587: All Generic Views are loosing args when you pass args and kwargs into
urlpattern

-------------------------------------+-------------------------------------
Reporter: Adrian | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: ListView, CBV, | Triage Stage:
generic, | Unreviewed
Has patch: 0 | Needs documentation: 0

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

* cc: Adrian (added)


Old description:

> When I have in my urlpatterns args and kwargs the ListView is loosing
> args (it's returning empty tuple)
>

> {{{
> url(r"^(\w+)/test1/(?P<pk>[0-9]+)/list/$", SamplesListView.as_view(),
> name='list_view'),
> }}}
>
> Simple code for my view:
>

> {{{
> class SamplesListView(ListView):
> model = Sample
> template_name = 'samples/samples_list.html'
>
> def get(self, request, project_name, *args, **kwargs):
> print("project_name", project_name)
> return super().get(self, request, project_name, *args, **kwargs)
> }}}
>

> It works ok when I pass only args or kwargs into url.

New description:

When I have in my urlpatterns args and kwargs the ListView is loosing args
(it's returning empty tuple)


{{{
url(r"^(\w+)/test1/(?P<pk>[0-9]+)/list/$", SamplesListView.as_view(),
name='list_view'),
}}}

Simple code for my view:


{{{
class SamplesListView(ListView):
model = Sample
template_name = 'samples/samples_list.html'

def get(self, request, project_name, *args, **kwargs):
print("project_name", project_name)
return super().get(self, request, project_name, *args, **kwargs)
}}}


It works ok when I pass only args or kwargs into url.

THE PROBLEM occurs in ALL generic view (CreateView, UpdateView,
DeleteVIew, ListView)

--

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

Django

unread,
Sep 14, 2017, 5:05:13 AM9/14/17
to django-...@googlegroups.com
#28587: All Generic Views are loosing args when you pass args and kwargs into
urlpattern
-------------------------------------+-------------------------------------
Reporter: Adrian | Owner: nobody
Type: Bug | Status: new
Component: Generic views | Version: 1.11
Severity: Normal | Resolution:
Keywords: ListView, CBV, | Triage Stage:
generic, | Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

Based on the documentation, I'm not sure if this is a bug. There's
[https://docs.djangoproject.com/en/dev/topics/http/urls/#the-matching-
grouping-algorithm a note] that says, "Here’s the algorithm the URLconf
parser follows, with respect to named groups vs. non-named groups in a
regular expression: If there are any named arguments, it will use those,
ignoring non-named arguments." which seems to be what's happening here.
The behavior isn't specific to generic views. If you use a function-based
view, you'll see the same thing.

I'm not sure the reason for that behavior and if changing it is feasible,
but it does seem unintuitive. On the other hand, is there a reason you
must mix args and kwargs in the URL pattern? Do you want to look into
writing a patch?

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

Django

unread,
Sep 25, 2017, 9:22:21 AM9/25/17
to django-...@googlegroups.com
#28587: All Generic Views are loosing args when you pass args and kwargs into
urlpattern
-------------------------------------+-------------------------------------
Reporter: Adrian | Owner: nobody
Type: Bug | Status: closed

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

Keywords: ListView, CBV, | Triage Stage:
generic, | 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


--
Ticket URL: <https://code.djangoproject.com/ticket/28587#comment:4>

Reply all
Reply to author
Forward
0 new messages