[Django] #18305: force_update/force_insert not passed up the inheritance chain in .save()

9 views
Skip to first unread message

Django

unread,
May 12, 2012, 5:54:46 AM5/12/12
to django-...@googlegroups.com
#18305: force_update/force_insert not passed up the inheritance chain in .save()
----------------------------------------------+--------------------
Reporter: akaariai | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
When saving a model, the force_update and force_insert are not passed up
to parent model saves in model.save(). For example:
{{{
class Place(models.Model):
name = TextField()

class Restaurant(Place):
serves_pizza = models.BooleanField()

r = Restaurant.objects.create(name='Pizzeria pizza-kebab',
serves_pizza=True)
r.serves_pizza = False
r.save(force_update=True)
}}}
Now, the r is updated correctly. Then, when saving the Place, the
force_update isn't passed to the save_base, and thus the Place is first
queried - so, the force_update isn't honored.

The same is true for force_insert. However, in this case it is possible
that the force_insert is meant only for the Restaurant. You can currently
do this:
{{{
p = Place.objects.create(name='p')
r = Restaurant(place=p, serves_pizza=False)
r.save(force_insert=True)
}}}
This would however be impossible if the force_insert would be passed up
the inheritance chain.

Fixing the force_update case seems clear - however the force_insert case
needs at least some consideration for backwards compatibility reasons.

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

Django

unread,
May 12, 2012, 7:05:26 AM5/12/12
to django-...@googlegroups.com
#18305: force_update/force_insert not passed up the inheritance chain in .save()
-------------------------------------+-------------------------------------
Reporter: akaariai | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Design
Keywords: | decision needed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by akaariai):

* needs_better_patch: => 0
* needs_docs: => 0
* needs_tests: => 0
* stage: Unreviewed => Design decision needed


Comment:

Patches for force_update and force_insert fixes available at:
https://github.com/akaariai/django/tree/ticket_18305 (just force_update)
and https://github.com/akaariai/django/tree/ticket_18305_both (contains
also force_insert).

I am marking this DDN, as I am not sure if fixing the force_insert can be
considered backwards compatible. If there were a way to save only the
child model (the restaurant), then this would be easier to accept, as we
could add "do this instead:" to the release notes.

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

Django

unread,
Apr 7, 2013, 1:17:40 PM4/7/13
to django-...@googlegroups.com
#18305: force_update/force_insert not passed up the inheritance chain in .save()
-------------------------------------+-------------------------------------

Reporter: akaariai | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) | Resolution:
Severity: Normal | Triage Stage: Accepted
Keywords: | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by Alex):

* stage: Design decision needed => Accepted


Comment:

Marking as accpted, at least 50% of this is an obvious bug ;)

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

Django

unread,
Mar 6, 2020, 11:38:01 AM3/6/20
to django-...@googlegroups.com
#18305: force_update/force_insert not passed up the inheritance chain in .save()
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Abhijeet Viswa):

I believe this can be closed since from Django 1.5, `save()` does an
update and on failure does an insert. At least for default UUIDs (#29260,
#29129) force_insert is honored for both classes. (I vaguely remember it
to be the same for AutoField in PostgreSQL as well).

--
Ticket URL: <https://code.djangoproject.com/ticket/18305#comment:3>

Django

unread,
Mar 9, 2020, 8:55:55 AM3/9/20
to django-...@googlegroups.com
#18305: force_update/force_insert not passed up the inheritance chain in .save()
-------------------------------------+-------------------------------------
Reporter: Anssi Kääriäinen | Owner: nobody
Type: Bug | Status: closed

Component: Database layer | Version: master
(models, ORM) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

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


Comment:

Fixed in 6b4834952dcce0db5cbc1534635c00ff8573a6d8.

--
Ticket URL: <https://code.djangoproject.com/ticket/18305#comment:4>

Reply all
Reply to author
Forward
0 new messages