Opened 5 years ago

Closed 5 years ago

Last modified 2 months ago

#21838 closed New feature (wontfix)

What about adding a .reload() method to the QuerySet API?

Reported by: fero@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.6
Severity: Normal Keywords: queryset
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no


Sometimes it is needed to reload data from database backend. It could be necessary in example to benefit of some values type-casting applied by the database backend module.

In various Django projects I developed I find useful a simple method QuerySet.reload() like this:

    def reload(self):
        """Reload QuerySet from backend."""
        pks_list = self.values_list('pk')
        return self.model.objects.filter(pk__in=pks_list)

Change History (3)

comment:1 Changed 5 years ago by Aymeric Augustin

Resolution: wontfix
Status: newclosed

This will be very inefficient for large querysets. I'm -1 on this implementation.

As far as I know, the easiest way to reload a QuerySet is simply qs.filter().

It will clone the queryset and wipe the result cache.

You may get different rows if the database has changed since the QuerySet was first evaluated. That's the behavior I would expect.

comment:2 Changed 5 years ago by fero@…

Thanks I checked it out, I didn't know about this feature.

comment:3 Changed 2 months ago by Rich Rauenzahn

This is a duplicate of #22553 filed a year later that suggests using .all(), and fixes the docs to point that feature out.

Last edited 2 months ago by Tim Graham (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top