#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 , 15 years ago
comment:2 by , 15 years ago
milestone: | → 1.2 |
---|---|
Triage Stage: | Unreviewed → Accepted |
Given the potential to accidentally nuke data, I'm pushing this one to a 1.2 blocker.
comment:3 by , 15 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 , 15 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 , 15 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
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.
Note: when I save by a ModelForm.