Code

Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#13293 closed (fixed)

r12900 breaks extra() with additional select clauses (Only applies to MySQL SQLCompiler)

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

Description (last modified by ramiro)

[12900] breaks the following query:

Page.objects.filter(...).extra(select={'_url_length': 'LENGTH(_cached_url)'}).order_by('-_url_length')[0]

LENGTH(_cached_url) is prepended to the list of fields which should be selected, which makes the row tuple one element longer than the fields tuple:

http://code.djangoproject.com/browser/django/trunk/django/db/backends/mysql/compiler.py#L6

Note that this bug only manifests itself under the following conditions:

  1. The first model field is an AutoField
  2. The second field is a (Null)?BooleanField
  3. The retrieved model has a PK of 1L (0L would also work, but auto incrementing primary key fields never have a value of 0L)

The resulting model instance has True instead of 1L as its PK.

Attachments (1)

13293.patch (2.2 KB) - added by mk 4 years ago.
Now with a regression test

Download all attachments as: .zip

Change History (6)

Changed 4 years ago by mk

Now with a regression test

comment:1 Changed 4 years ago by mk

  • Has patch set
  • Keywords MySQL added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Summary changed from r12900 breaks extra() with additional select clauses to r12900 breaks extra() with additional select clauses (Only applies to MySQL SQLCompiler)

comment:2 Changed 4 years ago by ramiro

  • Description modified (diff)

(reformatted description)

comment:3 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

comment:4 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [12939]) Fixed #13293 -- Corrected a problem with the MySQL handling of boolean return values when a query has an extra() clause. Thanks to mk for the report and draft patch.

comment:5 Changed 3 years ago by jacob

  • milestone 1.2 deleted

Milestone 1.2 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.