Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#13261 closed (worksforme)

SQL Update VS extra() or filter()

Reported by: Stephane Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords: sql update extra filter
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



I add one of this two filters on the query with a get_query_set() in a manager:

  • qset = qset.filter(site=settings.SITE_ID)
  • qset = qset.extra(where=['site_id = %s' % settings.SITE_ID])

All fine when I try to perform a SELECT, but when I do an UPDATE, the site_id are in the SET (UPDATE ... SET site_id = 1 WHERE ...) of the query and not in the WHERE (UPDATE ... SET ... WHERE site_id = 1).


Change History (6)

comment:1 Changed 9 years ago by anonymous

Note: when I save by a ModelForm.

comment:2 Changed 9 years ago by Russell Keith-Magee

milestone: 1.2
Triage Stage: UnreviewedAccepted

Given the potential to accidentally nuke data, I'm pushing this one to a 1.2 blocker.

comment:3 Changed 9 years ago by anonymous

Stephane, I've tried adding a test for this but I can't seem to hit this bug. Can you please confirm whether the bug is only triggered when using ModelForms?

comment:4 Changed 9 years ago by Alex Gaynor

I don't see how this is possible. extra where clause items are placed in self.where on teh query, like every filter.

comment:5 Changed 9 years ago by Russell Keith-Magee

Resolution: worksforme
Status: newclosed

Ok, now that I've tried to replicate, I can't make sense of this either. @Stéphane -- if you can provide a test case (i.e., an example of actual models and queries where this problem occurs), please reopen.

comment:6 Changed 7 years ago by Jacob

milestone: 1.2

Milestone 1.2 deleted

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