#33375: Admin changelist_formset does not use the Admin queryset
----------------------------------+--------------------------------------
     Reporter:  François Freitag  |                    Owner:  nobody
         Type:  Bug               |                   Status:  closed
    Component:  contrib.admin     |                  Version:  dev
     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 François.

 Can I ask you to dig a bit deeper, I'm not sure the test is right...

 The relevant section from the `changelist_view`:

 {{{
         # Handle POSTed bulk-edit data.
         if request.method == 'POST' and cl.list_editable and '_save' in
 request.POST:
             if not self.has_change_permission(request):
                 raise PermissionDenied
             FormSet = self.get_changelist_formset(request)
             modified_objects = self._get_list_editable_queryset(request,
 FormSet.get_default_prefix())
             formset = cl.formset = FormSet(request.POST, request.FILES,
 queryset=modified_objects)
             if formset.is_valid():
 }}}

 
[https://github.com/django/django/blob/03cadb912c78b769d6bf4a943a2a35fc1d952960/django/contrib/admin/options.py#L1772-L1778
 src]

 Adding the required `_save` to the `POST` data, we enter the block here,
 but despite having the right queryset, we don't have any forms, the form
 isn't valid:

 {{{
 (Pdb) modified_objects
 <QuerySet [<SoftDeletable: SoftDeletable object (1)>, <SoftDeletable:
 SoftDeletable object (2)>]>
 (Pdb) formset.queryset
 <QuerySet [<SoftDeletable: SoftDeletable object (1)>, <SoftDeletable:
 SoftDeletable object (2)>]>
 (Pdb) formset.is_valid()
 False
 (Pdb) formset.forms
 []
 (Pdb)
 }}}

 I guess this is the missing management form data (but I've run out of time
 to dig as it is).

 If you look into `_get_list_editable_queryset()`, you'll see that
 `self.get_queryset()` **is** used, which gives us the hoped for
 `modified_objects` queryset.

 No doubt you're seeing something, but there's not enough quite yet to see
 what it is (with available time).
 I'll mark as needsinfo. Please reopen when you can add more.
 Thanks.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/073.8517c748f7cb813ed6b0c04a4c2b0307%40djangoproject.com.

Reply via email to