Opened 15 years ago
Closed 10 years ago
#12268 closed Bug (duplicate)
[PATCH] can't do %s on extra select
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | select extra escape |
Cc: | anssi.kaariainen@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | yes |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There are times when you want to send to the database manager %s, an example of this usage would be converting from time string to epoch inside the database it self, for doing this you can use a line like: qs=qs.extra(select={'timestamp': "strftime(\"%%s\", time, 'utc')"}) (sqlite3).
Problem with this is that django detects %s in the select argument of extra and then waits for a select_params, unfortunately there's no escape been taken into account. The patch attached fixed this by detecting %%s as a valid escape sequence.
Attachments (2)
Change History (10)
by , 15 years ago
Attachment: | django_fixpercent_s_on_extra.patch added |
---|
comment:1 by , 15 years ago
Exactly the same problem, I have to feed a sqlite DB with a "strftime('%s',date)".
When I saw the '... avoid using the substring "%%s"...' in the documentation, I first thought 'well, so there must be another way to give this pattern, let's have a look at the source' ... but no.
Manuel, your patch works great! Thanks
(I know, my comment may be only a me-too, but it's a support to Manuel and a vote to have this ticket processed)
comment:2 by , 15 years ago
Needs documentation: | set |
---|---|
Needs tests: | set |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 15 years ago
As from version 1.2, this patch is still necessary, but not sufficient:
See also the patch in #13648
comment:4 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:5 by , 14 years ago
by , 13 years ago
Attachment: | 12268_regex.diff added |
---|
comment:7 by , 13 years ago
Cc: | added |
---|---|
Needs tests: | unset |
Version: | 1.1 → SVN |
Attached patch should fix this in a way that %s needs a param, %%s does not, %%%s does need and so on. The patch is based on regular expressions. According to my performance tests it is slightly faster than the original patch, but slightly slower than current implementation.
Tests attached. Does this really need documentation? Isn't it expected behavior that %%s is escaped?
this patch fixes the bug described.