An example *without* custom primary key (correct behavior):
{{{
class Parent(models.Model):
title = models.TextField()
class Child(Parent):
body = models.TextField()
>> Child.objects.create()
1. INSERT INTO "app_parent" ("title") VALUES ('') RETURNING
"app_parent"."id"
2. INSERT INTO "app_child" ("parent_ptr_id", "body") VALUES (1, '')
}}}
An example *with* custom primary key (incorrect behavior):
{{{
class Parent(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False
)
title = models.TextField()
class Child(Parent):
body = models.TextField()
>> Child.objects.create()
1. UPDATE "app_parent" SET "title" = '' WHERE "app_parent"."id" =
'd750cfdd-ae7b-48a6-a2e0-d49e70e28686'::uuid
2. INSERT INTO "app_parent" ("id", "title") VALUES ('d750cfdd-ae7b-
48a6-a2e0-d49e70e28686'::uuid, '')
3. INSERT INTO "app_child" ("parent_ptr_id", "body") VALUES ('d750cfdd-
ae7b-48a6-a2e0-d49e70e28686'::uuid, '')
}}}
Python 3.6, PostgreSQL 9.6
--
Ticket URL: <https://code.djangoproject.com/ticket/29129>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* stage: Unreviewed => Accepted
Comment:
That does look unexpected. Reproduced at
cb7860ccedb199cb221c9e084b5104978b246356.
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:1>
* owner: nobody => Ashaba John
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:2>
Comment (by user0007):
Replying to [comment:2 Ashaba John]:
Any chance to see fix for that in 2.1 release?
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:3>
Comment (by Ashaba John):
Replying to [comment:3 user0007]:
> Replying to [comment:2 Ashaba John]:
> Any chance to see fix for that in 2.1 release?
Hey,
Sorry for the delayed implementation. Will work on it and we should have
it in the 2.1 release. Thanks
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:4>
* owner: Ashaba John => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:5>
* status: new => closed
* resolution: => duplicate
Comment:
Closing as a duplicate of #29260 because the issue has nothing to do with
MTI and the other ticket has a larger discussion around how it should be
solved.
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:2>
* cc: Simon Charette (added)
* status: closed => new
* resolution: duplicate =>
Comment:
#31297 was opened and is a duplicate of this. This still occurs in Django
3.0. Reproduced at a6b3938afc0204093b5356ade2be30b461a698c5. It looks like
this use-case wasn't picked up as part of #29260. Possibly related to
#18305.
Simon, re-opening and CC-ing you to ask your opinion. (Thanks!)
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:3>
* cc: Abhijeet Viswa (added)
Comment:
CC'ing myself since I reported #31297. Didn't know about this ticket while
creating that one.
I'm up for fixing this issue if it is accepted.
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:4>
Comment (by Simon Charette):
Carlton, I agree that it's its own issue and that it's highly related to
#18305.
I'd say the fact that `save(force_insert=True)` doesn't work **is** a
duplicate of #18305 and the fact `save()` doesn't result in the same
optimization as #29260 when a primary key default is defined in MTI is an
omission of #29260.
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:5>
Comment (by Carlton Gibson):
Cheers Simon.
> I'm up for fixing this issue if it is accepted.
Abhijeet, if you'd like to assign yourself and take a look that would be
great. Reach out if you need any input.
Thanks.
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:6>
* owner: nobody => Abhijeet Viswa
* status: new => assigned
Comment:
Thank you. I'll come up with a patch soon.
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:7>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/12496 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:8>
* version: 2.0 => master
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:9>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"babd4126853e48594b61e8db71a83d7bdd929b9c" babd4126]:
{{{
#!CommitTicketReference repository=""
revision="babd4126853e48594b61e8db71a83d7bdd929b9c"
Fixed #29129 -- Skipped UPDATE when adding a model instance with inherited
primary key that has a default.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/29129#comment:10>