#18306: Deferred models should automatically issue update_fields when saving
-------------------------------------+-------------------------------------
     Reporter:  akaariai             |                    Owner:  akaariai
         Type:                       |                   Status:  new
  Cleanup/optimization               |                  Version:  master
    Component:  Database layer       |               Resolution:
  (models, ORM)                      |             Triage Stage:  Accepted
     Severity:  Normal               |      Needs documentation:  0
     Keywords:                       |  Patch needs improvement:  1
    Has patch:  1                    |                    UI/UX:  0
  Needs tests:  0                    |
Easy pickings:  0                    |
-------------------------------------+-------------------------------------

Comment (by niwi):

 You're absolutely right! The state can not be save on _meta attribute!

 I use the first aproach (store deferred fields on
 `modelinstance._state.deferred_fields`), because the second aproache not
 works correctlly. `self.__class__.__dict__` always contains
 `DeferredAttribute`, has been modified the field value or not.

 With my changes and your changes merged, fails two tests with unexpected
 number of queries:

 {{{
 ======================================================================
 FAIL: test_update_fields_fk_defer
 (modeltests.update_only_fields.tests.UpdateOnlyFieldsTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/home/niwi/django/tests/modeltests/update_only_fields/tests.py",
 line 101, in test_update_fields_fk_defer
     e1.save()
   File "../django/test/testcases.py", line 273, in __exit__
     executed, self.num
 AssertionError: 2 queries executed, 1 expected
 }}}


 Generated queries:
 {{{
 (0.000) SELECT "update_only_fields_person"."id",
 "update_only_fields_employee"."person_ptr_id" FROM
 "update_only_fields_employee" INNER JOIN "update_only_fields_person" ON
 ("update_only_fields_employee"."person_ptr_id" =
 "update_only_fields_person"."id") WHERE
 "update_only_fields_employee"."person_ptr_id" = 1 ; args=(1,)
 (0.000) UPDATE "update_only_fields_employee" SET "profile_id" = 2 WHERE
 "update_only_fields_employee"."person_ptr_id" IN (SELECT
 U0."person_ptr_id" FROM "update_only_fields_employee" U0 WHERE
 U0."person_ptr_id" = 1 ); args=(2, 1)
 }}}


 {{{
 ======================================================================
 FAIL: test_update_fields_inheritance_defer
 (modeltests.update_only_fields.tests.UpdateOnlyFieldsTests)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File "/home/niwi/django/tests/modeltests/update_only_fields/tests.py",
 line 89, in test_update_fields_inheritance_defer
     e1.save()
   File "../django/test/testcases.py", line 273, in __exit__
     executed, self.num
 AssertionError: 4 queries executed, 1 expected

 ----------------------------------------------------------------------
 }}}

 Generated queries:

 {{{
 (0.000) SELECT "update_only_fields_person"."id",
 "update_only_fields_employee"."person_ptr_id" FROM
 "update_only_fields_employee" INNER JOIN "update_only_fields_person" ON
 ("update_only_fields_employee"."person_ptr_id" =
 "update_only_fields_person"."id") WHERE
 "update_only_fields_employee"."person_ptr_id" = 1 ; args=(1,)
 (0.000) UPDATE "update_only_fields_person" SET "name" = Linda WHERE
 "update_only_fields_person"."id" = 1 ; args=('Linda', 1)
 (0.000) SELECT "update_only_fields_employee"."person_ptr_id",
 "update_only_fields_employee"."profile_id" FROM
 "update_only_fields_employee" INNER JOIN "update_only_fields_person" ON
 ("update_only_fields_employee"."person_ptr_id" =
 "update_only_fields_person"."id") WHERE
 "update_only_fields_employee"."person_ptr_id" = 1 ; args=(1,)
 (0.000) UPDATE "update_only_fields_employee" SET "profile_id" = 1 WHERE
 "update_only_fields_employee"."person_ptr_id" IN (SELECT
 U0."person_ptr_id" FROM "update_only_fields_employee" U0 WHERE
 U0."person_ptr_id" = 1 ); args=(1, 1)
 }}}


 I'm not sure it's appropriate behavior. But not for sure what would be
 appropriate.
 All changes are in the branch mentioned in my first comment.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/18306#comment:8>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to