Opened 5 years ago

Closed 5 years ago

Last modified 3 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: UI/UX:

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 Changed 5 years ago by anonymous

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Note: when I save by a ModelForm.

comment:2 Changed 5 years ago by russellm

  • milestone set to 1.2
  • Triage Stage changed from Unreviewed to Accepted

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

comment:3 Changed 5 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 5 years ago by Alex

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 5 years ago by russellm

  • Resolution set to worksforme
  • Status changed from new to 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.

comment:6 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

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