Edgewall Software

Note: this page documents the 1.0 version of Trac, see 0.12/TracQuery if you need the previous version

Trac Ticket Queries


In addition to reports, Trac provides support for custom ticket queries, used to display lists of tickets meeting a specified set of criteria.

To configure and execute a custom query, switch to the View Tickets module from the navigation bar, and select the Custom Query link.


When you first go to the query page the default filter will display tickets relevant to you:

  • If logged in then all open tickets it will display open tickets assigned to you.
  • If not logged in but you have specified a name or email address in the preferences then it will display all open tickets where your email (or name if email not defined) is in the CC list.
  • If not logged and no name/email defined in the preferences then all open issues are displayed.

Current filters can be removed by clicking the button to the left with the minus sign on the label. New filters are added from the pulldown lists at the bottom corners of the filters box ('And' conditions on the left, 'Or' conditions on the right). Filters with either a text box or a pulldown menu of options can be added multiple times to perform an or of the criteria.

You can use the fields just below the filters box to group the results based on a field, or display the full description for each ticket.

Once you've edited your filters click the Update button to refresh your results.

Clicking on one of the query results will take you to that ticket. You can navigate through the results by clicking the Next Ticket or Previous Ticket links just below the main menu bar, or click the Back to Query link to return to the query page.

You can safely edit any of the tickets and continue to navigate through the results using the Next/Previous/Back to Query links after saving your results. When you return to the query any tickets which were edited will be displayed with italicized text. If one of the tickets was edited such that it no longer matches the query criteria the text will also be greyed. Lastly, if a new ticket matching the query criteria has been created, it will be shown in bold.

The query results can be refreshed and cleared of these status indicators by clicking the Update button again.

Saving Queries

Trac allows you to save the query as a named query accessible from the reports module. To save a query ensure that you have Updated the view and then click the Save query button displayed beneath the results. You can also save references to queries in Wiki content, as described below.

Note: one way to easily build queries like the ones below, you can build and test the queries in the Custom report module and when ready - click Save query. This will build the query string for you. All you need to do is remove the extra line breaks.

Note: you must have the REPORT_CREATE permission in order to save queries to the list of default reports. The Save query button will only appear if you are logged in as a user that has been granted this permission. If your account does not have permission to create reports, you can still use the methods below to save a query.

You may want to save some queries so that you can come back to them later. You can do this by making a link to the query from any Wiki page.

[query:status=new|assigned|reopened&version=1.0 Active tickets against 1.0]

Which is displayed as:

Active tickets against 1.0

This uses a very simple query language to specify the criteria (see Query Language).

Alternatively, you can copy the query string of a query and paste that into the Wiki link, including the leading ? character:

[query:?status=new&status=assigned&status=reopened&group=owner Assigned tickets by owner]

Which is displayed as:

Assigned tickets by owner

Using the [[TicketQuery]] Macro

The TicketQuery macro lets you display lists of tickets matching certain criteria anywhere you can use WikiFormatting.



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

Just like the query: wiki links, the parameter of this macro expects a query string formatted according to the rules of the simple ticket query language. This also allows displaying the link and description of a single ticket:


This is displayed as:

No SQL error display

A more compact representation without the ticket summaries is also available:

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

This is displayed as:

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

Finally, if you wish to receive only the number of defects that match the query, use the count parameter.

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

This is displayed as:


Customizing the table format

You can also customize the columns displayed in the table format (format=table) by using col≤field> - you can specify multiple fields and what order they are displayed by placing pipes (|) between the columns like below:


This is displayed as:

Full rows

In table format you can also have full rows by using rows≤field> like below:


This is displayed as:

Results (1 - 3 of 9702)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#11700 cantfix UnknownLocaleError: unknown locale 'locale' ikezi

How to Reproduce

While doing a GET operation on /prefs, Trac issued an internal error.

(please provide additional details here)

Request parameters:

{'panel_id': None}

User agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36

System Information

Trac 0.12.3
Babel 0.9.6
Genshi 0.6
mod_python 3.3.1
pysqlite 2.6.0
Python 2.7.3 (default, Apr 13 2012, 20:15:24)
[GCC 4.6.3 20120306 (Red Hat 4.6.3-2)]
pytz 2010h
setuptools 0.6
jQuery 1.4.4

Enabled Plugins

TracGanttCalendarPlugin 0.6.2

Python Traceback

Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/trac/web/main.py", line 522, in _dispatch_request
  File "/usr/lib/python2.7/site-packages/trac/web/main.py", line 243, in dispatch
    resp = chosen_handler.process_request(req)
  File "/usr/lib/python2.7/site-packages/trac/prefs/web_ui.py", line 77, in process_request
    template, data = chosen_provider.render_preference_panel(req, panel_id)
  File "/usr/lib/python2.7/site-packages/trac/prefs/web_ui.py", line 109, in render_preference_panel
    locales = map(Locale.parse, get_available_locales())
  File "/usr/lib/python2.7/site-packages/babel/core.py", line 212, in parse
    return cls(*parse_locale(identifier, sep=sep))
  File "/usr/lib/python2.7/site-packages/babel/core.py", line 137, in __init__
    raise UnknownLocaleError(identifier)
UnknownLocaleError: unknown locale 'locale'
#11697 fixed ReportModule uses magic number -1 where None should be used rjollos rjollos

I found this refactoring from a while back on one of my local branches. The use of -1 in ReportModule.process_request should be replaced with None in order to be more Pythonic. At least, that is the first thought I had.

#11696 fixed TypeError: 'Logger' object is not callable John Shue <john@…> John Shue <john@…>

How to Reproduce

While doing a GET operation on /timeline, Trac issued an internal error.

Additional details:

This error also occurs when accessing the /browser URL. The issue appears to be caused by a member name collision in the tracext.hg.backend.trac_ui class. The trac_ui class uses trac_ui.log to store a Logger object, but the mercurial.ui base class is using log as a member function:

 def log(self, service, *msg, **opts):
        '''hook for logging facility extensions

        service should be a readily-identifiable subsystem, which will
        allow filtering.
        message should be a newline-terminated string to log.

The exception is raised when the mercurial.tags._readtagcache function is expecting trac_ui.log to be a function, when it is an instance of Logger. Here is the code from _readtagcache:

           'resolved %d tags cache entries from %d manifests in %0.4f '
           len(cachefnode), len(newheads), duration)

I was able to fix the error by altering the code in backend.py to rename the trac_ui.log member to trac_ui._log:

  • backend.py

    old new  
    181181    def __init__(self, *args, **kwargs): 
    182182        ui.__init__(self, *args) 
    183183        self.setconfig('ui', 'interactive', 'off') 
    184         self.log = kwargs.get('log', args and args[0].log or None) 
     184        self._log = kwargs.get('log', args and args[0]._log or None) 
    186186    def write(self, *args, **opts): 
    187187        for a in args: 
    188             self.log.info('(mercurial status) %s', a) 
     188            self._log.info('(mercurial status) %s', a) 
    190190    def write_err(self, *args, **opts): 
    191191        for a in args: 
    192             self.log.warn('(mercurial warning) %s', a) 
     192            self._log.warn('(mercurial warning) %s', a) 
    194194    def plain(self, *args, **kw): 
    195195        return False # so that '[hg] hgrc' file can specify [ui] options 

Request parameters:


User agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.131 Safari/537.36

System Information

Trac 1.0
Docutils 0.11
Genshi 0.7 (with speedups)
Mercurial 3.0
mod_wsgi 3.4 (WSGIProcessGroup WSGIApplicationGroup %{GLOBAL})
Pygments 1.6
pysqlite 2.6.0
Python 2.7.6 (default, May 15 2014, 18:23:58)
[GCC 4.2.1 Compatible FreeBSD Clang 3.3 (tags/RELEASE_33/final 183502)]
pytz 2014.3
setuptools 2.0.1
jQuery 1.7.2

Enabled Plugins


Python Traceback

Traceback (most recent call last):
  File "build/bdist.freebsd-10.0-RELEASE-i386/egg/trac/web/main.py", line 497, in _dispatch_request
  File "build/bdist.freebsd-10.0-RELEASE-i386/egg/trac/web/main.py", line 233, in dispatch
  File "build/bdist.freebsd-10.0-RELEASE-i386/egg/trac/web/chrome.py", line 1000, in render_template
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/core.py", line 184, in render
    return encode(generator, method=method, encoding=encoding, out=out)
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/output.py", line 58, in encode
    for chunk in iterator:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/output.py", line 350, in __call__
    for kind, data, pos in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/output.py", line 829, in __call__
    for kind, data, pos in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/output.py", line 669, in __call__
    for kind, data, pos in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/output.py", line 774, in __call__
    for kind, data, pos in chain(stream, [(None, None, None)]):
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/output.py", line 594, in __call__
    for ev in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/core.py", line 289, in _ensure
    for event in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/core.py", line 289, in _ensure
    for event in stream:
  File "build/bdist.freebsd-10.0-RELEASE-i386/egg/trac/web/chrome.py", line 1137, in _strip_accesskeys
    for kind, data, pos in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/core.py", line 289, in _ensure
    for event in stream:
  File "build/bdist.freebsd-10.0-RELEASE-i386/egg/trac/web/chrome.py", line 1126, in _generate
    for kind, data, pos in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/base.py", line 618, in _include
    for event in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/markup.py", line 378, in _match
    ctxt, start=idx + 1, **vars):
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/markup.py", line 378, in _match
    ctxt, start=idx + 1, **vars):
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/markup.py", line 326, in _match
    for event in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/base.py", line 558, in _flatten
    for kind, data, pos in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/core.py", line 289, in _ensure
    for event in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/path.py", line 588, in _generate
    subevent = next()
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/base.py", line 618, in _include
    for event in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/markup.py", line 315, in _strip
    event = next()
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/base.py", line 558, in _flatten
    for kind, data, pos in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/core.py", line 289, in _ensure
    for event in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/path.py", line 588, in _generate
    subevent = next()
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/base.py", line 618, in _include
    for event in stream:
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/markup.py", line 315, in _strip
    event = next()
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/base.py", line 578, in _flatten
    result = _eval_expr(data, ctxt, vars)
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/base.py", line 289, in _eval_expr
    retval = expr.evaluate(ctxt)
  File "/usr/local/lib/python2.7/site-packages/Genshi-0.7-py2.7-freebsd-10.0-RELEASE-p3-i386.egg/genshi/template/eval.py", line 177, in evaluate
    return eval(self.code, _globals, {'__data__': data})
  File "/usr/local/www/apache22/trac/eggs/Trac-1.0-py2.7.egg-tmp/trac/timeline/templates/timeline.html", line 49, in <Expression u"event.render('title', context)">
    <span class="time">${format_time(event.date, 'short')}</span> ${event.render('title', context)}
  File "build/bdist.freebsd-10.0-RELEASE-i386/egg/trac/timeline/web_ui.py", line 355, in <lambda>
    provider.render_timeline_event(context, field, event)
  File "build/bdist.freebsd-10.0-RELEASE-i386/egg/trac/versioncontrol/web_ui/changeset.py", line 1037, in render_timeline_event
    for name in cset.get_tags():
  File "/usr/home/jshue/working/mercurial-plugin/tracext/hg/backend.py", line 1322, in get_tags
    return [self.repos.to_u(t) for t in self.ctx.tags()]
  File "/usr/local/lib/python2.7/site-packages/mercurial/context.py", line 369, in tags
    return self._repo.nodetags(self._node)
  File "/usr/local/lib/python2.7/site-packages/mercurial/localrepo.py", line 675, in nodetags
    if not self._tagscache.nodetagscache:
  File "/usr/local/lib/python2.7/site-packages/mercurial/util.py", line 287, in __get__
    result = self.func(obj)
  File "/usr/local/lib/python2.7/site-packages/mercurial/localrepo.py", line 598, in _tagscache
    cache.tags, cache.tagtypes = self._findtags()
  File "/usr/local/lib/python2.7/site-packages/mercurial/localrepo.py", line 635, in _findtags
    tagsmod.findglobaltags(self.ui, self, alltags, tagtypes)
  File "/usr/local/lib/python2.7/site-packages/mercurial/tags.py", line 31, in findglobaltags
    (heads, tagfnode, cachetags, shouldwrite) = _readtagcache(ui, repo)
  File "/usr/local/lib/python2.7/site-packages/mercurial/tags.py", line 261, in _readtagcache
    len(cachefnode), len(newheads), duration)
TypeError: 'Logger' object is not callable
1 2 3 4 5 6 7 8 9 10 11

Query Language

query: TracLinks and the [[TicketQuery]] macro both use a mini “query language” for specifying query filters. Basically, the filters are separated by ampersands (&). Each filter then consists of the ticket field name, an operator, and one or more values. More than one value are separated by a pipe (|), meaning that the filter matches any of the values. To include a literal & or | in a value, escape the character with a backslash (\).

The available operators are:

= the field content exactly matches one of the values
~= the field content contains one or more of the values
^= the field content starts with one of the values
$= the field content ends with one of the values

All of these operators can also be negated:

!= the field content matches none of the values
!~= the field content does not contain any of the values
!^= the field content does not start with any of the values
!$= the field content does not end with any of the values

The date fields created and modified can be constrained by using the = operator and specifying a value containing two dates separated by two dots (..). Either end of the date range can be left empty, meaning that the corresponding end of the range is open. The date parser understands a few natural date specifications like "3 weeks ago", "last month" and "now", as well as Bugzilla-style date specifications like "1d", "2w", "3m" or "4y" for 1 day, 2 weeks, 3 months and 4 years, respectively. Spaces in date specifications can be left out to avoid having to quote the query string.

created=2007-01-01..2008-01-01 query tickets created in 2007
created=lastmonth..thismonth query tickets created during the previous month
modified=1weekago.. query tickets that have been modified in the last week
modified=..30daysago query tickets that have been inactive for the last 30 days

See also: TracTickets, TracReports, TracGuide

Last modified 3 weeks ago Last modified on Jul 11, 2014 11:02:54 AM