Opened 12 years ago

Closed 4 years ago

#18305 closed Bug (fixed)

force_update/force_insert not passed up the inheritance chain in .save()

Reported by: Anssi Kääriäinen Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When saving a model, the force_update and force_insert are not passed up to parent model saves in 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

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)

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.

Change History (4)

comment:1 by Anssi Kääriäinen, 12 years ago

Triage Stage: UnreviewedDesign decision needed

Patches for force_update and force_insert fixes available at: (just force_update) and (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.

comment:2 by Alex Gaynor, 11 years ago

Triage Stage: Design decision neededAccepted

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

comment:3 by Abhijeet Viswa, 4 years ago

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

comment:4 by Mariusz Felisiak, 4 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top