#25475: Database function srtftime with argument %W fails in 1.9a1
----------------------------------------------+---------------------------
     Reporter:  vtbassmatt                    |      Owner:  nobody
         Type:  Bug                           |     Status:  new
    Component:  Database layer (models, ORM)  |    Version:  1.9a1
     Severity:  Normal                        |   Keywords:  func strftime
 Triage Stage:  Unreviewed                    |  Has patch:  0
Easy pickings:  0                             |      UI/UX:  0
----------------------------------------------+---------------------------
 I have a database function to annotate the week of a date. It worked in
 1.8 but breaks in 1.9a1, failing with a "ValueError: unsupported format
 character 'W'" exception.

 {{{
 class Week(Func):
     function = 'strftime'
     template = "%(function)s('%%W',%(expressions)s)"

 def data_last_n_weeks(user, week_count):
     assert week_count > 0, "week_count must be greater than 0"
     assert week_count < 52, "week_count must be less than 52"

     today = date.today()
     most_recent_monday = today - timedelta(days=(today.isoweekday()-1))
     start_date = most_recent_monday - timedelta(days=7*(week_count-1))

     data = user.serving_set.filter(date__range=(start_date, today)
             ).annotate(week=Week('date',
 output_field=IntegerField())).values(
             'week').annotate(amt=Sum('amount'), cost=Sum('cost'))

     return data
 }}}

 yields

 {{{
   File "/Users/[me]/Projects/[proj]/ENV/lib/python3.4/site-
 packages/django/db/backends/sqlite3/operations.py", line 133, in
 last_executed_query
     return sql % params
 ValueError: unsupported format character 'W' (0x57) at index 18
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25475>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/053.a7e23b1c94d7a1602c07b726aa9af89f%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to