Opened 17 years ago

Closed 16 years ago

#2902 closed defect (fixed)

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

Reported by: Beau Hartshorne <beau@…> Owned by: nobody
Component: Database layer (models, ORM) Version:
Severity: normal Keywords: qs-rf-fixed
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

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

Change History (10)

comment:1 by Beau Hartshorne <beau@…>, 17 years ago

Component: Admin interfaceDatabase wrapper

comment:2 by Michael Radziej <mir@…>, 17 years ago

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 comment:3 by Beau Hartshorne <beau@…>, 17 years ago

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

comment:4 by Michael Radziej <mir@…>, 17 years ago

Triage Stage: UnreviewedDesign 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.

comment:5 by Beau Hartshorne <beau@…>, 17 years ago

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?

comment:6 by Malcolm Tredinnick, 17 years ago

Keywords: qs-rf added

comment:7 by Malcolm Tredinnick, 16 years ago

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

comment:8 by Malcolm Tredinnick, 16 years ago

Keywords: qs-rf-fixed added; qs-rf removed
Triage Stage: Design decision neededAccepted

comment:9 by Malcolm Tredinnick, 16 years ago

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

comment:10 by Malcolm Tredinnick, 16 years ago

Resolution: fixed
Status: newclosed

(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

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