#21454: Ignoring certain fields on INSERT and UPDATE queries
-------------------------------------+-------------------------------------
     Reporter:  mpessas              |                    Owner:  mpessas
         Type:  New feature          |                   Status:  assigned
    Component:  Database layer       |                  Version:  master
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  oracle               |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by owais):

 I am continuing work on this as part of
 https://github.com/django/django/pull/5904. My intention is to only
 support backends that actually support this feature i.e, Postgresql using
 `RETURNING` and Oracle using `RETURNING INTO`. I can follow up with
 another PR to "simulate" the behavior on backends that don't support it.
 I've yet to write any docs or test cases.

 The changes introduce 3 new field options.

 == `return_on_insert` ==
 When set to `True`, django will load the value from the database column
 along with the insert statement and set it on the model. This is a noop on
 mysql and sqlite.


 == `return_on_update` ==
 When set to `True`, django will load the value from the database column
 along with the update statement and set it on the model. This is a noop on
 mysql and sqlite.


 == `delegated` ==
 When set to `True`, django completely skips this field from insert and
 update operations and let's the database set a value. It also sets
 `return_on_update` and `return_on_insert` to `True` if no explicit value
 is passed for them.

 I think the combination of these three options covers almost every option
 except when all the fields are delegated. In this case, the update
 statement is never executed as `UPDATE` statement does not work without
 `SET` clause and we can't intelligently decide whether to use the existing
 value in update or not.

 One possible way to reduce the impact of edge case would be to add another
 field called `delegate_if_None` which would delegate the field to database
 only when current value of the field is set to None. I'm not sure if such
 a rare case should be supported though. It can easily by solved by setting
 `return_on_insert` and `return_on_update` to True and then setting default
 value or adding logic in database triggers.

--
Ticket URL: <https://code.djangoproject.com/ticket/21454#comment:20>
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/065.3a0e5b79c439e96948aebbcd3073d13e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to