Great, thank you! Although I'm more than willing to upgrade, I still wonder if this fix will be backported to 1.7… On 28 Mar 2015 02:15, "Tim Graham" <[email protected]> wrote:
> This is fixed in Django 1.8. See the fifth item in > https://docs.djangoproject.com/en/dev/releases/1.8/#models. > > On Friday, March 27, 2015 at 5:38:15 PM UTC-4, Gergely Polonkai wrote: >> >> Hello, >> >> I’d like to execute the following code: >> >> Booking.objects.filter(start_ts__isnull = False, end_ts__isnull = >> False).extra(select = {'amount': "strftime('%s', end_ts) - strftime('%s', >> start_ts)"}) >> >> However, in the shell, I get the following error: >> >> Traceback (most recent call last): File "<console>", line 1, in <module> >> File "/home/polesz/Projects/duckbook/venv/lib/python3.4/ >> site-packages/django/db/models/query.py", line 835, in extra >> clone.query.add_extra(select, select_params, where, params, tables, >> order_by) File "/home/polesz/Projects/duckbook/venv/lib/python3.4/ >> site-packages/django/db/models/sql/query.py", line 1744, in add_extra >> entry_params.append(next(param_iter)) StopIteration >> >> I have tried doubling the percent signs (%%s) and escaping them with a >> backslash (\%s), but neither helped. I also looked at this answer >> <http://stackoverflow.com/a/18143147/1305139>[1], but that solution >> doesn’t work with QuerySet.extra() (or I just miss the point). >> >> What is the correct way to solve this? >> >> I also tried to use select_params like this: >> >> Booking.objects.filter(start_ts__isnull = False, end_ts__isnull = >> False).extra(select = {'amount': "strftime('%s', end_ts) - strftime(%s, >> start_ts)"}, select_params = ['%s', '%s']) >> >> but regardless the usage of quote signs, the resulting query has \'%s\', >> which gives an SQL error, of course. >> >> Best, >> Gergely >> >> [1] http://stackoverflow.com/a/18143147/1305139 >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/django-users. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/fa509ee1-6bb2-43c8-a1a1-e12ad70a123f%40googlegroups.com > <https://groups.google.com/d/msgid/django-users/fa509ee1-6bb2-43c8-a1a1-e12ad70a123f%40googlegroups.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CACczBU%2B8FvXtCHe1bLUYjU51OU8JV4bxEXThQcWMxL5euc44gg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.

