[Django] #22553: Add ability to refresh queryset

15 views
Skip to first unread message

Django

unread,
May 1, 2014, 7:25:55 AM5/1/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
----------------------------------------------+--------------------
Reporter: giggaflop@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer (models, ORM) | Version: 1.6
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
I propose adding a Queryset method '.refresh()' which will clear the
built-in cache on any queryset passed to it.

I suggest an initial implementation of:


{{{
def refresh(self, *args, **kwargs):
"""
Returns a new QuerySet instance with the args ANDed to the
existing
set.
"""
self._result_cache = None
return self
}}}

Reason this is requested:

When I'm using modelformsets I typically find the need to refresh the
queryset that is used by the ModelFormset.

To do this I perform the following action:


{{{
updated_formset = ConciergeUserPoolFormset(request.POST)
if updated_formset.is_valid():
updated_formset.save()
queryset = updated_formset.get_queryset()
# we need an updated queryset, not the cached version. set the
results cache to None to force re-fetch
queryset._result_cache = None
updated_formset = ConciergeUserPoolFormset(queryset=queryset)
}}}

This is not an obvious solution to the issue of updating a ModelFormset or
forcing a queryset update in general, it also uses a private method of the
Queryset object which I would prefer to avoid.

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

Django

unread,
May 1, 2014, 12:05:37 PM5/1/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------------+-------------------------------------

Reporter: giggaflop@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | Triage Stage:
Keywords: | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

Maybe `_clone()` already does what you need.

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

Django

unread,
Jun 24, 2014, 7:43:07 AM6/24/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------------+-------------------------------------

Reporter: giggaflop@… | Owner: nobody
Type: New feature | Status: new
Component: Database layer | Version: 1.6
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by timo):

* stage: Unreviewed => Accepted


Comment:

I guess we probably don't want to document an underscore method. I wonder
if there is any reason not to rename it (with deprecation) to `clone()` or
something similar?

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

Django

unread,
Jul 1, 2014, 9:39:07 AM7/1/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------+------------------------------------

Reporter: giggaflop@… | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by akaariai):

* component: Database layer (models, ORM) => Documentation
* easy: 0 => 1


Comment:

.all() can be used for this. Seems like this isn't documented, so lets do
that. The right place seems to be
https://docs.djangoproject.com/en/dev/ref/models/querysets/#django.db.models.query.QuerySet.all.

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

Django

unread,
Jul 8, 2014, 5:27:51 PM7/8/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------+------------------------------------

Reporter: giggaflop@… | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by nikisweeting@…):

I'd be happy to write a little blurb in the docs showing how to use .all()
for refreshing a QuerySet. I'm new to contributing to here though, how do
I go about submitting my proposed documentation amendment?

--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:4>

Django

unread,
Jul 8, 2014, 6:06:16 PM7/8/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------+------------------------------------

Reporter: giggaflop@… | Owner: nobody
Type: New feature | Status: new
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by timo):

Fortunately, we have
[https://docs.djangoproject.com/en/dev/internals/contributing/ extensive
docs] that explains how to contribute. :-)

--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:5>

Django

unread,
Jul 26, 2014, 9:00:32 AM7/26/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------+------------------------------------
Reporter: giggaflop@… | Owner: dhoffman
Type: New feature | Status: assigned

Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by dhoffman):

* status: new => assigned
* owner: nobody => dhoffman


--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:6>

Django

unread,
Jul 26, 2014, 10:05:48 AM7/26/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------+------------------------------------
Reporter: giggaflop@… | Owner: dhoffman
Type: New feature | Status: assigned
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by dhoffman):

Completed: https://github.com/django/django/pull/2974

--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:7>

Django

unread,
Jul 26, 2014, 10:23:16 AM7/26/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------------+-------------------------------------

Reporter: giggaflop@… | Owner: dhoffman
Type: New feature | Status: assigned
Component: Documentation | Version: 1.6
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timo):

* has_patch: 0 => 1
* stage: Accepted => Ready for checkin


Comment:

Looks good. Don't forget to check "Has patch" so the ticket appears in the
review queue. Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:8>

Django

unread,
Jul 26, 2014, 10:27:58 AM7/26/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------------+-------------------------------------
Reporter: giggaflop@… | Owner: dhoffman
Type: New feature | Status: closed
Component: Documentation | Version: 1.6
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"6d5daa30cf29d0bada0586213ecb2959152566b4"]:
{{{
#!CommitTicketReference repository=""
revision="6d5daa30cf29d0bada0586213ecb2959152566b4"
Fixed #22553 -- Added refreshing queryset info to docs.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:9>

Django

unread,
Jul 26, 2014, 10:28:18 AM7/26/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------------+-------------------------------------
Reporter: giggaflop@… | Owner: dhoffman
Type: New feature | Status: closed
Component: Documentation | Version: 1.6
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"e3a99357cba5085f5ae937920529292edafc5c7a"]:
{{{
#!CommitTicketReference repository=""
revision="e3a99357cba5085f5ae937920529292edafc5c7a"
[1.6.x] Fixed #22553 -- Added refreshing queryset info to docs.

Backport of 6d5daa30cf from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:10>

Django

unread,
Jul 26, 2014, 10:28:19 AM7/26/14
to django-...@googlegroups.com
#22553: Add ability to refresh queryset
-------------------------------------+-------------------------------------
Reporter: giggaflop@… | Owner: dhoffman
Type: New feature | Status: closed
Component: Documentation | Version: 1.6
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
Has patch: 1 | checkin
Needs tests: 0 | Needs documentation: 0
Easy pickings: 1 | Patch needs improvement: 0
| UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"1ef544f91f0d4be3f44ae7fd0498530e57a9b160"]:
{{{
#!CommitTicketReference repository=""
revision="1ef544f91f0d4be3f44ae7fd0498530e57a9b160"
[1.7.x] Fixed #22553 -- Added refreshing queryset info to docs.

Backport of 6d5daa30cf from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/22553#comment:11>

Reply all
Reply to author
Forward
0 new messages