#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/049.91a38e6ab84b8b2f9f9a79a3675ee1bf%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to