﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29129	Child model updates parent model with empty fields making an extra query in multi-inheritance when parent model has custom PK	user0007	Abhijeet Viswa	"While creating a new model object (using multi-inheritance model => `Child(Parent)`), Django does an extra update query setting parent model fields to empty values. This situation occurs *only* if we define a custom primary key in a parent model (eg. as an UUID field).

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"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed		Simon Charette Abhijeet Viswa	Ready for checkin	1	0	0	0	0	0
