Opened 6 years ago

Closed 6 years ago

#28820 closed Bug (fixed)

update() produces extra query with proxy model

Reported by: Yan Mitrofanov Owned by: Yan Mitrofanov
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no


Assume we have these models:

class Chef(models.Model):
    name = models.CharField(max_length=50)

    class Meta:
        db_table = "chef"

class ProxyChef(Chef):

    class Meta:
        proxy = True

If we execute update query on proxy


We get two queries

SELECT "chef"."id" FROM "chef" WHERE "chef"."id" = 1
UPDATE "chef" SET "name" = 'William' WHERE "chef"."id" IN (1)

The first one is totally unnecessary.

Change History (3)

comment:1 Changed 6 years ago by Yan Mitrofanov

Owner: changed from nobody to Yan Mitrofanov

comment:2 Changed 6 years ago by Tim Graham

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:3 Changed 6 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 54e5c4a0:

Fixed #28820 -- Eliminated an extra query with QuerySet.update() on proxy models.

Note: See TracTickets for help on using tickets.
Back to Top