[Django] #21838: What about adding a .reload() method to the QuerySet API?

29 views
Skip to first unread message

Django

unread,
Jan 21, 2014, 5:25:56 AM1/21/14
to django-...@googlegroups.com
#21838: What about adding a .reload() method to the QuerySet API?
----------------------------------------------+----------------------
Reporter: fero@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.6
Severity: Normal | Keywords: queryset
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
----------------------------------------------+----------------------
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)
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/21838>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 21, 2014, 5:32:21 AM1/21/14
to django-...@googlegroups.com
#21838: What about adding a .reload() method to the QuerySet API?
-------------------------------------+-------------------------------------
Reporter: fero@… | Owner: nobody
Type: New feature | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: queryset | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by aaugustin):

* status: new => closed
* needs_better_patch: => 0
* resolution: => wontfix
* needs_tests: => 0
* needs_docs: => 0


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/21838#comment:1>

Django

unread,
Jan 22, 2014, 6:14:37 PM1/22/14
to django-...@googlegroups.com
#21838: What about adding a .reload() method to the QuerySet API?
-------------------------------------+-------------------------------------
Reporter: fero@… | Owner: nobody

Type: New feature | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) | Resolution: wontfix
Severity: Normal | Triage Stage:
Keywords: queryset | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by fero@…):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/21838#comment:2>

Django

unread,
Aug 20, 2018, 2:01:16 PM8/20/18
to django-...@googlegroups.com
#21838: What about adding a .reload() method to the QuerySet API?
-------------------------------------+-------------------------------------
Reporter: fero@… | Owner: nobody

Type: New feature | Status: closed
Component: Database layer | Version: 1.6
(models, ORM) |
Severity: Normal | Resolution: wontfix

Keywords: queryset | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Rich Rauenzahn):

FYI: This is a duplicate of https://code.djangoproject.com/ticket/22553
filed a year later that suggests using .all(), and fixes the docs to point
that feature out.

--
Ticket URL: <https://code.djangoproject.com/ticket/21838#comment:3>

Reply all
Reply to author
Forward
0 new messages