Opened 14 years ago

Closed 14 years ago

Last modified 13 years ago

#13261 closed (worksforme)

SQL Update VS extra() or filter()

Reported by: Stephane Owned by: nobody
Component: Database layer (models, ORM) Version: dev
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

Description

Hi,

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).

Stéphane

Change History (6)

comment:1 by anonymous, 14 years ago

Note: when I save by a ModelForm.

comment:2 by Russell Keith-Magee, 14 years ago

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 by anonymous, 14 years ago

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 by Alex Gaynor, 14 years ago

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 by Russell Keith-Magee, 14 years ago

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 by Jacob, 13 years ago

milestone: 1.2

Milestone 1.2 deleted

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