nephila / djangocms-blog

django CMS blog application - Support for multilingual posts, placeholders, social network meta tags and configurable apphooks
https://djangocms-blog.readthedocs.io
BSD 3-Clause "New" or "Revised" License
392 stars 192 forks source link

When removing a blog post i get cannot call delete() after .distinct(). #683

Closed svandeneertwegh closed 1 year ago

svandeneertwegh commented 2 years ago

I cannot remove a blog post. I get "Cannot call delete() after .distinct()."

Steps to reproduce

djangocms_blog==1.2.3 django==3.2.5

Apparently this repo is not ready for django 3.2.5.. When i switch back to django==1.2.9 it does work..

petrklus commented 2 years ago

Seeing the same here

petrklus commented 2 years ago
# admin deletion fix
from djangocms_blog.admin import PostAdmin
def new_get_queryset_admin(self, request):
    qs = super(PostAdmin, self).get_queryset(request)
    sites = self.get_restricted_sites(request)
    if sites.exists():
        pks = list(sites.all().values_list("pk", flat=True))
        qs = qs.filter(sites__in=pks)
    return qs #.distinct() DJ32 fix
PostAdmin.get_queryset = new_get_queryset_admin

@svandeneertwegh if still relevant, I am using the above monkey-patch to get deletion working again in the list view. Not seeing any other side-effects with my simple setup.

petrklus commented 2 years ago

Perhaps @yakky will know more - is the distinct actually required? (present here: https://github.com/nephila/djangocms-blog/blob/develop/djangocms_blog/admin.py#L439)

I do not seem to be observing any ill-effects after our monkey-patch.

szabozoltan69 commented 2 years ago

For me the same issue was fixed via setting

Django = ">=3.2,<3.3"

in pyproject.toml, so it selected itself Django 3.2.13.

adrien-delhorme commented 2 years ago

The bug is still present for me with djangocms-blog==1.2.3 and Django==3.2.13.

JohnYan2017 commented 2 years ago

any solution? django bug?

petrklus commented 2 years ago

any solution? django bug?

I would not call it a bug, it is more of a behaviour change that we need to adapt to.

yakky commented 1 year ago

Thanks for reporting this, it's fixed in #735