Opened 5 years ago

Closed 5 years ago

#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 by Joon Hwan 김준환, 5 years ago

Description: modified (diff)

comment:2 by Joon Hwan 김준환, 5 years ago

Description: modified (diff)

comment:3 by Mariusz Felisiak, 5 years ago

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 by Mariusz Felisiak, 5 years ago

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 by Hasan Ramezani, 5 years ago

Owner: changed from nobody to Hasan Ramezani
Status: newassigned

comment:6 by Hasan Ramezani, 5 years ago

Has patch: set
Version 0, edited 5 years ago by Hasan Ramezani (next)

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

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