#630739 trac: sorting on custom field label with multiple words generates "Report execution failed..."

#630739#5
Date:
2011-06-16 18:47:34 UTC
From:
To:
*** Please type your report below this line ***

Our trac installation (0.11.7) has a custome field, named due_date
with label "Due Date". The following is a query that presents Due Date
as a column:

SELECT p.value AS __color__,
    id AS ticket, summary, t.type AS type,
    owner, status,
    time AS created,
    changetime AS _changetime, description AS _description,
    reporter AS _reporter,
    c.value as 'Due Date'
   FROM ticket t
   LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
   left join ticket_custom c on (t.id = c.ticket and c.name = 'due_date')
   WHERE status <> 'closed' and t.type = 'task'
   ORDER BY CAST(p.value AS integer), milestone, t.type, time

When this query is executed and the user clicks on the Due Date colume to sort
the query result, the following error will show up:

Report execution failed: near "Date": syntax error

Further investigation using trac's debug level logging shows the failed
query is

2011-06-13 15:17:21,004 Trac[report] DEBUG: Query SQL: SELECT * FROM
( SELECT p.value AS __color__,
    id AS ticket, summary, t.type AS type,
    owner, status,
    time AS created,
    changetime AS _changetime, description AS _description,
    reporter AS _reporter,
    c.value as 'Due Date'
   FROM ticket t
   LEFT JOIN enum p ON p.name = t.priority AND p.type = 'priority'
   left join ticket_custom c on (t.id = c.ticket and c.name = 'due_date')
   WHERE status <> 'closed' and t.type = 'task'
   ORDER BY CAST(p.value AS integer), milestone, t.type, time
  ) AS tab  ORDER BY Due Date DESC LIMIT 100 OFFSET 0

The problem is in the last line. The label "Due Date" contains a space
and should be quoted. Replacing it with the following line

  ) AS tab  ORDER BY `Due Date` DESC LIMIT 100 OFFSET 0

The following fix may not be the right thing but it works
--- report.py.orig	2011-06-13 15:26:15.000000000 -0400
+++ report.py	2011-06-13 14:57:57.000000000 -0400
@@ -571,7 +571,7 @@
                  if '__group__' in cols:
                      order_cols.append('__group__')
                  if sort_col in cols:
-                    order_cols.append(sort_col)
+                    order_cols.append("`" + sort_col + "`")
                  else:
                      raise TracError(_('Query parameter "sort=%(sort_col)s" '
                                        ' is invalid', sort_col=sort_col))

Note: This bug doesn't exist in 0.12.

#630739#10
Date:
2020-01-09 06:08:43 UTC
From:
To:
Dear submitter,

as the package trac has just been removed from the Debian archive
unstable we hereby close the associated bug reports.  We are sorry
that we couldn't deal with your issue properly.

For details on the removal, please see https://bugs.debian.org/948052

The version of this package that was in Debian prior to this removal
can still be found using http://snapshot.debian.org/.

Please note that the changes have been done on the master archive and
will not propagate to any mirrors until the next dinstall run at the
earliest.

This message was generated automatically; if you believe that there is
a problem with it please contact the archive administrators by mailing
ftpmaster@ftp-master.debian.org.

Debian distribution maintenance software
pp.
Scott Kitterman (the ftpmaster behind the curtain)