Edgewall Software

This page documents the 1.2 (latest stable) release. Documentation for other releases can be found here.

TicketQuery Wiki Macro

The TicketQuery macro lets you display ticket information anywhere that accepts WikiFormatting. The query language used by the [[TicketQuery]] macro is described in the TracQuery page.



Wiki macro listing tickets that match certain criteria.

This macro accepts a comma-separated list of keyed parameters, in the form "key=value".

If the key is the name of a field, the value must use the syntax of a filter specifier as defined in TracQuery#QueryLanguage. Note that this is not the same as the simplified URL syntax used for query: links starting with a ? character. Commas (,) can be included in field values by escaping them with a backslash (\).

Groups of field constraints to be OR-ed together can be separated by a literal or argument.

In addition to filters, several other named parameters can be used to control how the results are presented. All of them are optional.

The format parameter determines how the list of tickets is presented:

  • list — the default presentation is to list the ticket ID next to the summary, with each ticket on a separate line.
  • compact — the tickets are presented as a comma-separated list of ticket IDs.
  • count — only the count of matching tickets is displayed
  • rawcount — only the count of matching tickets is displayed, not even with a link to the corresponding query (since 1.1.1)
  • table — a view similar to the custom query view (but without the controls)
  • progress — a view similar to the milestone progress bars

The max parameter can be used to limit the number of tickets shown (defaults to 0, i.e. no maximum).

The order parameter sets the field used for ordering tickets (defaults to id).

The desc parameter indicates whether the order of the tickets should be reversed (defaults to false).

The group parameter sets the field used for grouping tickets (defaults to not being set).

The groupdesc parameter indicates whether the natural display order of the groups should be reversed (defaults to false).

The verbose parameter can be set to a true value in order to get the description for the listed tickets. For table format only. deprecated in favor of the rows parameter

The rows parameter can be used to specify which field(s) should be viewed as a row, e.g. rows=description|summary

The col parameter can be used to specify which fields should be viewed as columns. For table format only.

For compatibility with Trac 0.10, if there's a last positional parameter given to the macro, it will be used to specify the format. Also, using "&" as a field separator still works (except for order) but is deprecated.


Example Result Macro
Number of Triage tickets: 26 [[TicketQuery(status=new&milestone=,count)]]
Number of new tickets: 1039 [[TicketQuery(status=new,count)]]
Number of reopened tickets: 13 [[TicketQuery(status=reopened,count)]]
Number of assigned tickets: 43 [[TicketQuery(status=assigned,count)]]
Number of invalid tickets: 1506 [[TicketQuery(status=closed,resolution=invalid,count)]]
Number of worksforme tickets: 1400 [[TicketQuery(status=closed,resolution=worksforme,count)]]
Number of duplicate tickets: 2167 [[TicketQuery(status=closed,resolution=duplicate,count)]]
Number of wontfix tickets: 962 [[TicketQuery(status=closed,resolution=wontfix,count)]]
Number of fixed tickets: 4361 [[TicketQuery(status=closed,resolution=fixed,count)]]
Number of untriaged tickets (milestone unset): 29 [[TicketQuery(status!=closed,milestone=,count)]]
Total number of tickets: 12056 [[TicketQuery(count)]]
Number of tickets reported or owned by current user: 1813 [[TicketQuery(reporter=$USER,or,owner=$USER,count)]]
Number of tickets created this month: 5 [[TicketQuery(created=thismonth..,count)]]
Number of closed Firefox tickets: 13 [[TicketQuery(status=closed,keywords~=firefox,count)]]
Number of closed Opera tickets: 12 [[TicketQuery(status=closed,keywords~=opera,count)]]
Number of closed tickets affecting Firefox and Opera: 1 [[TicketQuery(status=closed,keywords~=firefox opera,count)]]
Number of closed tickets affecting Firefox or Opera: 24 [[TicketQuery(status=closed,keywords~=firefox|opera,count)]]
Number of tickets that affect Firefox or are closed and affect Opera: 25 [[TicketQuery(status=closed,keywords~=opera,or,keywords~=firefox,count)]]
Number of closed Firefox tickets that don't affect Opera: 1 [[TicketQuery(status=closed,keywords~=firefox -opera,count)]]
Last 3 modified tickets: #13174, #3676, #12458 [[TicketQuery(max=3,order=modified,desc=1,compact)]]

Details of ticket #1:


Ticket Owner Reporter
#1 anonymous
Summary Add a new project summary module.

Format: list


This is displayed as:

Wiki preview injects new lines
request for colour legend (or something similar) for ticket groups in reports
Ticket Dependencies
Link to diff of specifik wiki change instead of the page itself
All ticket modifications should be tracked in timeline
Installing on Windows, drive other than C:
Diffviewer should try to convert the text into utf-8.
merging of similar tickets
Python process sometimes hangs on Windows Server 2003
IE 5-6 over HTTPS broken downloads


This is displayed as:

No SQL error display

Format: compact

[[TicketQuery(version=0.6|0.7&resolution=duplicate, compact)]]

This is displayed as:

#181, #204, #226, #239, #351, #413, #450, #475, #519, #529

Format: count

[[TicketQuery(version=0.6|0.7&resolution=duplicate, count)]]

This is displayed as:


Format: progress


This is displayed as:


5 / 5


2 / 2


1 / 1

Format: table

You can choose the columns displayed in the table format (format=table) using col=<field>. You can specify multiple fields and the order they are displayed by placing pipes (|) between the columns:


This is displayed as:

Full rows

In table format you can specify full rows using rows=<field>:


This is displayed as:

Results (1 - 3 of 10961)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#13173 wontfix Abort previous search when starting new search anonymous

After clicking the Search button I sometimes notice I typed the search term wrong or forgot to change the search checkboxes. I fix it and click Search again. But then (because Trac search is a bit slow sometimes) the first search result arrives and is displayed, and my changes to the search term or checkboxes of my second search gets lost.

Is there a way to avoid losing the changed search parameters? Or just abort the first search when the second search is started? I don't know if this is technically possible.


#13172 cantfix Polish locale file (pl.js) missing in 1.2.3 wheel anonymous

Dear trac devs,

polish locale js file (pl.js) is not present in the Trac-1.2.3-py2-none-any.whl file:

wget "https://files.pythonhosted.org/packages/41/66/6adf72f889af8a16f8e32246c9db9d666826a6a7d267fd57fefd6095d238/Trac-1.2.3-py2-none-any.whl"

unzip -l Trac-1.2.3-py2-none-any.whl | grep /pl
   127813  2018-07-29 18:42   trac/locale/pl/LC_MESSAGES/messages.mo
    72865  2018-07-29 18:42   trac/locale/pl/LC_MESSAGES/tracini.mo

unzip -l Trac-1.2.3-py2-none-any.whl | grep pl.js | wc -l

is there any reason to not to have this file included in the whl file?

#13168 fixed Query._get_constraints() should not modify a list in req.args Jun Omae Jun Omae

I sometimes encounter IndexErrors from Query._get_constraints() on our production environment with private plugin which calls Query._get_constraints().

ERROR: Internal Server Error: <RequestWithSession "POST '/query'">, referrer 'https://example.org/query'
Traceback (most recent call last):
  File "/venv/lib/python2.7/site-packages/trac/web/main.py", line 554, in _dispatch_request
  File "/venv/lib/python2.7/site-packages/trac/web/main.py", line 257, in dispatch
    self._post_process_request(req, *resp)
  File "/venv/lib/python2.7/site-packages/trac/web/main.py", line 388, in _post_process_request
    resp = f.post_process_request(req, *resp)
  File "/vol/releases/20190322024230/share/plugins/XxxPlugin.egg/xxx/project/ticket/custom_field.py", line 626, in post_process_request
    if not mod._get_constraints(req) and 'order' not in req.args:
  File "/venv/lib/python2.7/site-packages/trac/ticket/query.py", line 1066, in _get_constraints
    del vals[idx]
IndexError: list assignment index out of range

Investigating the issue, it is caused by that Query._get_constraints() modifies a list in req.args and is called twice when a condition is removed.

I don't consider the method should modify a list in req.args.


  • trac/ticket/query.py

    diff --git a/trac/ticket/query.py b/trac/ticket/query.py
    index 3fbe171f1..80ca3c054 100644
    a b class QueryModule(Component):  
    10441044            # requested for clients without JavaScript
    10451045            add_num = None
    10461046            constraints = {}
    1047             for k, vals in req.args.iteritems():
     1047            for k in req.args:
    10481048                match = self.add_re.match(k)
    10491049                if match:
    10501050                    add_num = match.group(1)
    class QueryModule(Component):  
    10561056                clause_num = int(match.group('clause'))
    10571057                if field not in fields:
    10581058                    continue
    1059                 if not isinstance(vals, (list, tuple)):
    1060                     vals = [vals]
     1059                # use list() to avoid modification of a list in req.args
     1060                vals = list(req.args.getlist(k))
    10611061                if vals:
    10621062                    mode = req.args.get(k + '_mode')
    10631063                    if mode:
  • trac/ticket/tests/query.py

    diff --git a/trac/ticket/tests/query.py b/trac/ticket/tests/query.py
    index cb2d0fc6e..e8cce442c 100644
    a b ORDER BY COALESCE(c.%(ticket)s,'')='',c.%(ticket)s,t.id""" % quoted)  
    11081108        prop = req.chrome['script_data']['properties']['milestone']
    11091109        self.assertEqual({'label': 'Milestone', 'type': 'text'}, prop)
     1111    def test_get_constraints_keep_req_args(self):
     1112        arg_list = (('0_type', 'defect'), ('0_type', 'task'),
     1113                    ('0_type', 'enhancement'), ('rm_filter_0_type_1', '-'),
     1114                    ('1_type', 'task'))
     1115        req = MockRequest(self.env, method='POST', path_info='/query',
     1116                          arg_list=arg_list)
     1117        orig_args = arg_list_to_args(arg_list)
     1118        mod = QueryModule(self.env)
     1119        self.assertTrue(mod.match_request(req))
     1120        template, data, content_type = mod.process_request(req)
     1121        self.assertEqual([{'type': ['defect', 'enhancement']},
     1122                          {'type': ['task']}],
     1123                         data['query'].constraints)
     1124        self.assertEqual(orig_args, req.args)
    11121127class QueryLinksTestCase(unittest.TestCase):
1 2 3 4 5 6 7 8 9 10 11

See also: TracQuery, TracTickets, TracReports

Last modified 11 months ago Last modified on Jul 20, 2018, 2:54:29 AM
Note: See TracWiki for help on using the wiki.