[Django] #28974: Model.refresh_from_db() should pass the refreshed instance as a database hint

11 views
Skip to first unread message

Django

unread,
Dec 30, 2017, 9:29:32 PM12/30/17
to django-...@googlegroups.com
#28974: Model.refresh_from_db() should pass the refreshed instance as a database
hint
-------------------------------------+-------------------------------------
Reporter: Simon | Owner: nobody
Charette |
Type: | Status: new
Cleanup/optimization |
Component: Database | Version: master
layer (models, ORM) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
While reviewing the patch for #28918 and reflecting about #28939 I noticed
that the `refresh_from_db()` method
[https://github.com/django/django/blob/d065c92678f5d11a70b88e195c6357576eb3a2ef/django/db/models/base.py#L593
was duplicating] the work
[https://github.com/django/django/blob/d065c92678f5d11a70b88e195c6357576eb3a2ef/django/db/utils.py#L261-L263
the routers do] when an `instance` hint is provided.

I figured out that we we're better of using `db_manager(using,
hints={'instance': self})` in this case which would also have the benefit
of passing down `instance` as an hint to possibly defined custom routers.

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

Django

unread,
Dec 30, 2017, 9:40:37 PM12/30/17
to django-...@googlegroups.com
#28974: Model.refresh_from_db() should pass the refreshed instance as a database
hint
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9513 PR]

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

Django

unread,
Jan 2, 2018, 9:42:50 AM1/2/18
to django-...@googlegroups.com
#28974: Model.refresh_from_db() should pass the refreshed instance as a database
hint
-------------------------------------+-------------------------------------
Reporter: Simon Charette | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"f5a989e60394ac11f5dce886468a34533caefcbf" f5a989e6]:
{{{
#!CommitTicketReference repository=""
revision="f5a989e60394ac11f5dce886468a34533caefcbf"
Fixed #28974 -- Made refresh_from_db() hint routers about its instance.
}}}

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

Reply all
Reply to author
Forward
0 new messages