[Django] #29519: Django admin actions: _selected_action disregarded when `difference` is applied to queryset via filters

50 views
Skip to first unread message

Django

unread,
Jun 23, 2018, 6:27:53 AM6/23/18
to django-...@googlegroups.com
#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
-------------------------------------------+------------------------
Reporter: Andreas Galazis | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
I have an admin with filters where one of them is:
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class NegatedMyFiledFilter(MyFieldListFilter):
title = ('excluded Fields')
parameter_name = 'nonField'

def queryset(self, request, queryset):
if self.values():
queryset_to_negate = super(
NegatedMyFieldFilter, self
).queryset(request, queryset)
return queryset.difference(queryset_to_negate)
}}}
}}}
Where MyFieldListFilter is a filter that extends admin.SimpleListFilter
When the above filter is applied(alone or in combination with others)
_selected_action is not respected when applying an action and as a result
actions get applied to all records, not just the selected ones
As a hack I ended up doing in one of my custom actions :
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
qs_ids = queryset.values_list('pk', flat=True)
selected_ids = request.POST.getlist('_selected_action',qs_ids)
return TimeSheet.objects.filter(
pk__in=qs_ids,
).filter(pk__in=selected_ids).update(my_flag=True)
}}}
}}}
but I was expecting the framework to do the second filtering for me

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

Django

unread,
Jun 23, 2018, 6:29:32 AM6/23/18
to django-...@googlegroups.com
#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
---------------------------------+--------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 1.11
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Andreas Galazis):

* cc: Andreas Galazis (added)
* version: 2.0 => 1.11
* component: Uncategorized => contrib.admin


Old description:

New description:

The above happens in version 1.11.13

--

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

Django

unread,
Jun 23, 2018, 6:54:32 AM6/23/18
to django-...@googlegroups.com
#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
---------------------------------+--------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: Uncategorized | Status: new
Component: contrib.admin | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Description changed by Andreas Galazis:

Old description:

> The above happens in version 1.11.13

New description:

I have an admin with filters where one of them is:
{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
class NegatedMyFiledFilter(MyFieldListFilter):
title = ('excluded Fields')
parameter_name = 'nonField'

def queryset(self, request, queryset):
if self.values():
queryset_to_negate = super(
NegatedMyFieldFilter, self
).queryset(request, queryset)
return queryset.difference(queryset_to_negate)
}}}
}}}
Where MyFieldListFilter is a filter that extends admin.SimpleListFilter
When the above filter is applied(alone or in combination with others)
_selected_action is not respected when applying an action and as a result
actions get applied to all records, not just the selected ones

As a hack I ended up doing in one of my custom actions (although this is
applicable to all actions including build in ones like delete):


{{{
#!div style="font-size: 80%"
Code highlighting:
{{{#!python
qs_ids = queryset.values_list('pk', flat=True)
selected_ids = request.POST.getlist('_selected_action',qs_ids)
return TimeSheet.objects.filter(
pk__in=qs_ids,
).filter(pk__in=selected_ids).update(my_flag=True)
}}}
}}}
but I was expecting the framework to do the second filtering for me

The above happens in version 1.11.13

--

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

Django

unread,
Jun 24, 2018, 2:31:38 PM6/24/18
to django-...@googlegroups.com
#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
---------------------------------+--------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: Bug | Status: new

Component: contrib.admin | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Andreas Galazis):

* type: Uncategorized => Bug


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

Django

unread,
Jun 28, 2018, 7:50:00 PM6/28/18
to django-...@googlegroups.com
#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
---------------------------------+--------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 1.11
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Tim Graham):

Can you explain why Django is at fault and propose a fix?

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

Django

unread,
Jul 3, 2018, 4:51:04 AM7/3/18
to django-...@googlegroups.com
#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
---------------------------------+--------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.11
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------
Changes (by Carlton Gibson):

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


Comment:

Hi Andreas.

I can't see the issue with what you've provided here. Can you please
create a test case or a minimal project that reproduces the issue?

At that point we'll be able to assess if there's a genuine issue here, or
whether it's something else that's going on.

Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/29519#comment:5>

Django

unread,
May 4, 2021, 2:29:48 AM5/4/21
to django-...@googlegroups.com
#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
---------------------------------+--------------------------------------

Reporter: Andreas Galazis | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 1.11
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
---------------------------------+--------------------------------------

Comment (by Andreas Galazis):

Hello sorry for the late response. I didn't realize you requested for more
info(and I just stumbled on this ticket by accident today). Just for the
records: I think the issue had to do with the fact that difference / union
was locking the queryset therefore not being able to filter selected
entries afterwards. Feel free to keep it closed since (I think) its
documented

--
Ticket URL: <https://code.djangoproject.com/ticket/29519#comment:6>

Reply all
Reply to author
Forward
0 new messages