Opened 11 years ago

Closed 11 years ago

Last modified 6 years 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

Description

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 by Aymeric Augustin, 11 years ago

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 by fero@…, 11 years ago

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

comment:3 by Rich Rauenzahn, 6 years ago

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 6 years ago by Tim Graham (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top