Admin TypeError - Cannot call delete() after .distinct()

696 views
Skip to first unread message

Mike Dewhirst

unread,
Jul 2, 2021, 2:03:28 AM7/2/21
to Django users
Trying to delete a record in the Admin list view by checking the
checkbox and selecting the delete action and clicking [Go] the following
500 error happened.

It seems to be all within the Admin so I'm not sure how to proceed from
here.

Thanks for any hints

Mike

Traceback (most recent call last):
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\handlers\exception.py",
line 47, in inner
    response = get_response(request)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\core\handlers\base.py",
line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\options.py",
line 616, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\utils\decorators.py",
line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\views\decorators\cache.py",
line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\sites.py",
line 232, in inner
    return view(request, *args, **kwargs)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\utils\decorators.py",
line 43, in _wrapper
    return bound_method(*args, **kwargs)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\utils\decorators.py",
line 130, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\options.py",
line 1739, in changelist_view
    response = self.response_action(request,
queryset=cl.get_queryset(request))
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\options.py",
line 1408, in response_action
    response = func(self, request, queryset)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\actions.py",
line 45, in delete_selected
    modeladmin.delete_queryset(request, queryset)
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\options.py",
line 1109, in delete_queryset
    queryset.delete()
  File
"D:\Users\mike\envs\xxai\lib\site-packages\django\db\models\query.py",
line 728, in delete
    raise TypeError('Cannot call delete() after .distinct().')

Exception Type: TypeError at /admin/chemical/chemical/
Exception Value: Cannot call delete() after .distinct().

--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.


OpenPGP_signature

Jason

unread,
Jul 2, 2021, 8:30:44 AM7/2/21
to Django users

https://code.djangoproject.com/ticket/32682 might be the root cause, which was fixed end of April and part of the 3.2.1 release, doesn't seem like its been backported to 3.1

Sebastian Jung

unread,
Jul 2, 2021, 9:48:29 AM7/2/21
to django...@googlegroups.com
Hello Mike,

i don't understand why you want make a delete from a distict... Then you delete random entrys. When you want do delete dupletes then this is a wrong method to delete dupletes...

Regards

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4ceeffab-480a-aecd-a12d-01f183598d57%40dewhirst.com.au.

Mike Dewhirst

unread,
Jul 2, 2021, 10:16:21 AM7/2/21
to django...@googlegroups.com
Should have mentioned - I'm running 3.2.4

M



--
(Unsigned mail from my phone)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.

Mike Dewhirst

unread,
Jul 2, 2021, 10:22:34 AM7/2/21
to django...@googlegroups.com
Just looked at that ticket and it seems probable that is what is happening.

I'll be patient. 

Thanks for that

M

--
(Unsigned mail from my phone)



-------- Original message --------
From: Jason <jjohn...@gmail.com>
Date: 2/7/21 22:30 (GMT+10:00)
To: Django users <django...@googlegroups.com>
Subject: Re: Admin TypeError - Cannot call delete() after .distinct()


Reply all
Reply to author
Forward
0 new messages