[Django] #30281: Model.refresh_from_db() does not refresh related objects

192 views
Skip to first unread message

Django

unread,
Mar 22, 2019, 10:41:50 AM3/22/19
to django-...@googlegroups.com
#30281: Model.refresh_from_db() does not refresh related objects
-------------------------------------+-------------------------------------
Reporter: Alek96 | Owner: nobody
Type: Bug | Status: new
Component: Database | Version: 2.0
layer (models, ORM) |
Severity: Normal | Keywords: refresh_from_db
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
After testing my application with Django 2.0.13 I noticed few of my test
started failing (they were working on Django 2.1). After further
investigation, I figured out the problem was coming from
**refresh_from_db** method.

Here is a test that show the problem:

{{{
def test_error_on_refresh_from_db(self):
def add_one(id):
task_model = FakeTask.objects.get(id=id)
task_model.task_group.finished_tasks_number =
F('finished_tasks_number') + 1
task_model.task_group.save()
task_model.task_group.refresh_from_db()
task_model.save()
self.assertEqual(task_model.task_group.finished_tasks_number, 1)

task_group_model = FakeTaskGroup.objects.create()
task_model = FakeTask.objects.create(task_group=task_group_model)
add_one(task_model.id)
task_model.refresh_from_db()
self.assertEqual(task_model.task_group.finished_tasks_number, 1)
}}}

Here you can find the definition (light version) of the this models:

{{{
class FakeTaskGroup(models.Model):
finished_tasks_number = models.PositiveIntegerField(default=0)

class FakeTask(models.Model):
task_group = models.ForeignKey(FakeTaskGroup,
on_delete=models.CASCADE)
}}}

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

Django

unread,
Mar 22, 2019, 11:03:40 AM3/22/19
to django-...@googlegroups.com
#30281: Model.refresh_from_db() does not refresh related objects
-------------------------------------+-------------------------------------
Reporter: Aleksander Zamojski | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution: wontfix
Keywords: refresh_from_db | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

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

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


Comment:

Django 2.0 is end-of-life April 2019 and only receives security and data
loss fixes until then (but most likely there won't be another release).

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

Reply all
Reply to author
Forward
0 new messages