Django

Code

Ticket #2902 (closed: fixed)

Opened 2 years ago

Last modified 3 weeks ago

.extra()'s params list is incorrectly merged into the unordered select dictionary's %s slots.

Reported by: Beau Hartshorne <beau@hartshorne.ca> Assigned to: nobody
Component: Database wrapper Version:
Keywords: qs-rf-fixed Cc:
Triage Stage: Accepted Has patch: 0
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

.extra() expects a dictionary of extra select fields, and a list of query parameters to go with it. Since dictionaries are unordered, something like this fails:

.extra(select={'thingOne': 'REGEX %s', 'thingTwo': 'REGEX %s'}, params = (one, two))

I tried using a django.utils.datastructures.SortedDict, but that did not solve the problem.

More discussion: http://groups.google.com/group/django-users/browse_thread/thread/8ced145389650d62

Attachments

Change History

10/11/06 20:30:12 changed by Beau Hartshorne <beau@hartshorne.ca>

  • component changed from Admin interface to Database wrapper.

(follow-up: ↓ 3 ) 02/01/07 07:42:25 changed by Michael Radziej <mir@noris.de>

I don't understand what you try to do with the fields. I cannot do a SELECT REGEX 'one' FROM tablename, so, what should the generated SQL look like for your example case? Perhaps I'm only too dumb here, happens a lot recently ;-)

Or did you mean:

.extra(select={'thingOne': 'fieldname REGEX %s', ...}, params=...)

?

(in reply to: ↑ 2 ) 02/01/07 10:31:34 changed by Beau Hartshorne <beau@hartshorne.ca>

Replying to Michael Radziej <mir@noris.de>:

My SQL syntax is incorrect. You're right, this is what I meant:

.extra(select={'thingOne': 'fieldOne REGEX %s', 'thingTwo': 'fieldTwo REGEX %s'}, params = (one, two))

02/01/07 15:37:19 changed by Michael Radziej <mir@noris.de>

  • stage changed from Unreviewed to Design decision needed.

Thanks! As has been written in the mail thread, this is currently a limitation.

If you have any idea how to extend extra() so that you can use parameters within the SELECT dict, and still maintain compatibility to the old syntax, please add it to the ticket.

02/01/07 15:50:32 changed by Beau Hartshorne <beau@hartshorne.ca>

Sure, just switch to django.utils.datastructures.SortedDict all the way through, and deprecate native dicts if there's more than one key. That seems to make the most sense in terms of API compatiblity, but I'm not sure if that will cause any performance problems or if it's difficult to implement.

Thoughts?

09/13/07 16:37:41 changed by mtredinnick

  • keywords set to qs-rf.

10/23/07 23:22:23 changed by mtredinnick

(In [6603]) queryset-refactor: Added the ability to apply parameters to the select fragments in QuerySet?.extra(). Refs #2902

10/23/07 23:24:35 changed by mtredinnick

  • keywords changed from qs-rf to qs-rf-fixed.
  • stage changed from Design decision needed to Accepted.

04/02/08 03:30:11 changed by mtredinnick

Note that [7340] changed the solution from [6603], in case anybody was tracking this.

04/26/08 21:50:16 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [7477]) Merged the queryset-refactor branch into trunk.

This is a big internal change, but mostly backwards compatible with existing code. Also adds a couple of new features.

Fixed #245, #1050, #1656, #1801, #2076, #2091, #2150, #2253, #2306, #2400, #2430, #2482, #2496, #2676, #2737, #2874, #2902, #2939, #3037, #3141, #3288, #3440, #3592, #3739, #4088, #4260, #4289, #4306, #4358, #4464, #4510, #4858, #5012, #5020, #5261, #5295, #5321, #5324, #5325, #5555, #5707, #5796, #5817, #5987, #6018, #6074, #6088, #6154, #6177, #6180, #6203, #6658


Add/Change #2902 (.extra()'s params list is incorrectly merged into the unordered select dictionary's %s slots.)




Change Properties
Action