[Django] #31297: force_insert not respected by parent class with default primary key

11 views
Skip to first unread message

Django

unread,
Feb 22, 2020, 1:22:15 AM2/22/20
to django-...@googlegroups.com
#31297: force_insert not respected by parent class with default primary key
-------------------------------------+-------------------------------------
Reporter: Abhijeet | Owner: Abhijeet
Type: Bug | Status: assigned
Component: Database | Version: 3.0
layer (models, ORM) |
Severity: Normal | Keywords: force_insert mti
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Consider the following modesl:

{{{
class A(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4)
test = models.IntegerField()


class B(A):
test2 = models.IntegerField()
pass
}}}

{{{
b = B()
b.test = 10
b.test2 = 20
b.save(force_insert=True)
}}}
will generate the following update/insert statements for PostgreSQL:
{{{
UPDATE "save_force_insert_a"
SET "test" = 10
WHERE "save_force_insert_a"."uuid" =
'8275d9e0-c0fd-4489-b987-44b9dbe379b4'::UUID;


INSERT INTO "save_force_insert_a" ("uuid",
"test")
VALUES ('8275d9e0-c0fd-4489-b987-44b9dbe379b4'::UUID, 10);


INSERT INTO "save_force_insert_b" ("a_ptr_id",
"test2")
VALUES ('8275d9e0-c0fd-4489-b987-44b9dbe379b4'::UUID, 20);
}}}

It's the same even when saving a new instance of a model and the user
provides the UUID.

However, in the Model Instance Reference, it says the following:
```
Changed in Django 3.0:
Model.save() no longer attempts to find a row when saving a new Model
instance and a default value for the primary key is provided, and always
executes an INSERT.
```

It is expected that using a force_insert (and a value is provided
explicitly or as a default), force_insert should be respected by the
parents as well.
This isn't fully related to #18305. I believe that ticket also talks about
AutoField PKs.

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

Django

unread,
Feb 22, 2020, 12:03:17 PM2/22/20
to django-...@googlegroups.com
#31297: force_insert not respected by parent class with default primary key
-------------------------------------+-------------------------------------
Reporter: Abhijeet Viswa | Owner: Abhijeet
| Viswa
Type: Bug | Status: assigned
Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:

Keywords: force_insert mti | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by ChillarAnand:

Old description:

New description:

Consider the following modell:


It is expected that using a force_insert (and value is provided explicitly


or as a default), force_insert should be respected by the parents as well.

This isn't fully related to #18305. I believe that the ticket also talks
about AutoField PKs.

--

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

Django

unread,
Feb 22, 2020, 1:57:02 PM2/22/20
to django-...@googlegroups.com
#31297: force_insert not respected by parent class with default primary key
-------------------------------------+-------------------------------------
Reporter: Abhijeet Viswa | Owner: Abhijeet
| Viswa
Type: Bug | Status: assigned

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: force_insert mti | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> Consider the following modell:

> It is expected that using a force_insert (and value is provided


> explicitly or as a default), force_insert should be respected by the
> parents as well.

> This isn't fully related to #18305. I believe that the ticket also talks
> about AutoField PKs.

New description:

Consider the following models:


It is expected that using a force_insert (and value is provided explicitly


or as a default), force_insert should be respected by the parents as well.

This isn't fully related to #18305. I believe that the ticket also talks
about AutoField PKs.

--

Comment (by Abhijeet Viswa):

It seems my description of the ticket was poorly formatted. Thanks
@ChillarAnand for fixing it.

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

Django

unread,
Feb 25, 2020, 5:53:31 AM2/25/20
to django-...@googlegroups.com
#31297: force_insert not respected by parent class with default primary key
-------------------------------------+-------------------------------------
Reporter: Abhijeet Viswa | Owner: Abhijeet
| Viswa
Type: Bug | Status: closed

Component: Database layer | Version: 3.0
(models, ORM) |
Severity: Normal | Resolution: duplicate

Keywords: force_insert mti | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* status: assigned => closed
* resolution: => duplicate


Comment:

Thanks for the report.

The force_insert is not needed in the example. The results are the same
with and without it.

The example is identical to #29129. We'll discuss there.

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

Reply all
Reply to author
Forward
0 new messages