Giter Site home page Giter Site logo

Comments (3)

sathoro avatar sathoro commented on July 17, 2024

This is because of the implementation of all on SafeDeleteManager. It calls the queryset's all method, however Django's default implementation does not. Calling all on a queryset creates a clone. Clones do not copy over cached prefetch_related lookups.

This is what the Django source code looks like (django/db/models/manager.py), with a comment about why it doesn't call all:

def all(self):
    # We can't proxy this method through the `QuerySet` like we do for the
    # rest of the `QuerySet` methods. This is because `QuerySet.all()`
    # works by creating a "copy" of the current queryset and in making said
    # copy, all the cached `prefetch_related` lookups are lost. See the
    # implementation of `RelatedManager.get_queryset()` for a better
    # understanding of how this comes into play.
    return self.get_queryset()

I removed the all call and it no longer re-evaluates prefetch_related lookups but I'm wondering if it was calling all for a reason or if it is safe to remove?

from django-safedelete.

sathoro avatar sathoro commented on July 17, 2024

Here is what I have changed the SafeDeleteManager.all method to in order to support force_visibility and still keep the cached lookups.

def all(self, *args, **kwargs):
    force_visibility = kwargs.pop('force_visibility', None)

    qs = self.get_queryset()

    if force_visibility is not None:
        qs._safedelete_force_visibility = force_visibility

    return qs

from django-safedelete.

Gagaro avatar Gagaro commented on July 17, 2024

Thanks a lot and sorry for the delay, it's fixed on master.

from django-safedelete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.