#29260: Django makes an extra UPDATE query when custom PK is evaluating before
save.
-------------------------------------+-------------------------------------
Reporter: user0007 | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 2.0
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | 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 user0007:
Old description:
> Using model's instance:
>
> {{{
>
> class Account(models.Model):
> id = models.UUIDField(
> primary_key=True,
> default=uuid.uuid4,
> editable=False
> )
> title = models.TextField()
>
> >> account = Account()
> >> account.title = "abc"
> >> account.save()
>
> 1. UPDATE "app_account" SET "title" = \'\', WHERE "app_account"."id" =
> \'67c9327d-150e-419f-b493-0c2c59a045c3\'::uuid',
> 2. INSERT INTO "app_account" ("title", "id") VALUES (\'abc\', \'3d8c1b3c-
> 214a-4798-a0fa-d4c22c2b877f\'::uuid)
>
> }}}
>
> Using model's manager method:
>
> {{{
> >> Account.objects.create(title="abc")
>
> 1. INSERT INTO "app_account" ("title", "id") VALUES (\'abc\', \'3d8c1b3c-
> 214a-4798-a0fa-d4c22c2b877f\'::uuid)
> }}}
>
> Related issue? https://code.djangoproject.com/ticket/29129
New description:
Using a model's instance:
{{{
class Account(models.Model):
id = models.UUIDField(
primary_key=True,
default=uuid.uuid4,
editable=False
)
title = models.TextField()
>> account = Account()
>> account.title = "abc"
>> account.save()
1. UPDATE "app_account" SET "title" = \'\', WHERE "app_account"."id" =
\'67c9327d-150e-419f-b493-0c2c59a045c3\'::uuid',
2. INSERT INTO "app_account" ("title", "id") VALUES (\'abc\', \'3d8c1b3c-
214a-4798-a0fa-d4c22c2b877f\'::uuid)
}}}
Using a model's manager method:
{{{
>> Account.objects.create(title="abc")
1. INSERT INTO "app_account" ("title", "id") VALUES (\'abc\', \'3d8c1b3c-
214a-4798-a0fa-d4c22c2b877f\'::uuid)
}}}
Using a model's instance with `force_insert` argument:
{{{
>> account = Account()
>> account.title = "abc"
>> account.save(force_insert=true)
1. INSERT INTO "app_account" ("title", "id") VALUES (\'abc\', \'3d8c1b3c-
214a-4798-a0fa-d4c22c2b877f\'::uuid)
}}}
Related issue? https://code.djangoproject.com/ticket/29129
--
--
Ticket URL: <https://code.djangoproject.com/ticket/29260#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.5339e9e45ca53473b748849122e25396%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.