Opened 18 years ago
Closed 17 years ago
#2902 closed defect (fixed)
.extra()'s params list is incorrectly merged into the unordered select dictionary's %s slots.
Reported by: | 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 , 18 years ago
Component: | Admin interface → Database wrapper |
---|
follow-up: 3 comment:2 by , 18 years ago
comment:3 by , 18 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 , 18 years ago
Triage Stage: | Unreviewed → 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.
comment:5 by , 18 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 , 17 years ago
Keywords: | qs-rf added |
---|
comment:7 by , 17 years ago
comment:8 by , 17 years ago
Keywords: | qs-rf-fixed added; qs-rf removed |
---|---|
Triage Stage: | Design decision needed → Accepted |
comment:9 by , 17 years ago
comment:10 by , 17 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
(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
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:
?