#31148 closed Cleanup/optimization (fixed)

Raise a descriptive error on update()/delete() operations following QuerySet.union(), intersection(), and difference().

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

Description (last modified by Joon Hwan 김준환)

b_filter() seems to merge but does not apply to the actual update

q = M.objects.none()
q = q.union(M.objects.a_filter())
print(q)
q = q.union(M.objects.b_filter())
print(q)
q.update(name='foo')
<QuerySet [<M: M object (675)>]>
<QuerySet [<M: M object (675)>, <M: M object (773)>]>
UPDATE "m" SET "name" = "foo" WHERE `a_filter Conditional statement` ORDER BY U0."id" ASC  LIMIT 1); args=(...)

Change History (7)

comment:1 Changed 23 months ago by Joon Hwan 김준환

Description: modified (diff)

comment:2 Changed 23 months ago by Joon Hwan 김준환

Description: modified (diff)

comment:3 Changed 23 months ago by Mariusz Felisiak

Cc: Hasan Ramezani added
Summary: Can not update unioned queryset after union.Raise a descriptive error on update()/delete() operations following QuerySet.union(), intersection(), and difference()
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Version: 2.2master

This operation is unsupported, see documentation:

In addition, only LIMIT, OFFSET, COUNT(*), ORDER BY, and specifying columns (i.e. slicing, count(), order_by(), and values()/values_list()) are allowed on the resulting QuerySet.

but I agree that we should raise a descriptive error for update() and delete() (see related #27995).

comment:4 Changed 23 months ago by Mariusz Felisiak

Easy pickings: set
Summary: Raise a descriptive error on update()/delete() operations following QuerySet.union(), intersection(), and difference()Raise a descriptive error on update()/delete() operations following QuerySet.union(), intersection(), and difference().

comment:5 Changed 23 months ago by Hasan Ramezani

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:6 Changed 23 months ago by Hasan Ramezani

Has patch: set
Last edited 23 months ago by Mariusz Felisiak (previous) (diff)

comment:7 Changed 23 months ago by Mariusz Felisiak <felisiak.mariusz@…>

Resolution: fixed
Status: assignedclosed

In eef3ea8:

Fixed #31148 -- Added error messages on update()/delete() operations following union(), intersection(), and difference().

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