Opened 18 months ago

Closed 18 months ago

Last modified 17 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

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 (2)

comment:1 Changed 18 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

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 17 months ago by fero@…

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

Note: See TracTickets for help on using tickets.
Back to Top