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

Description

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

ProxyChef.objects.filter(id=1).update(name='William')

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 by Yan Mitrofanov, 6 years ago

Owner: changed from nobody to Yan Mitrofanov

comment:2 by Tim Graham, 6 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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

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