Edgewall Software

This page documents the 0.11 release. Documentation for other releases can be found here.

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.

Filters

When you first go to the query page the default filters will display all open tickets, or if you're logged in it will display open tickets assigned to you. Current filters can be removed by clicking the button to the right with the minus sign on the label. New filters are added from the pulldown list in the bottom-right corner of the filters box. 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

While Trac does not yet allow saving a named query and somehow making it available in a navigable list, you can save references to queries in Wiki content, as described below.

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.

Example:

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

This is displayed as:

#181
Wiki preview injects new lines
#204
request for colour legend (or something similar) for ticket groups in reports
#226
Ticket Dependencies
#239
Link to diff of specifik wiki change instead of the page itself
#351
All ticket modifications should be tracked in timeline
#413
Installing on Windows, drive other than C:
#450
Diffviewer should try to convert the text into utf-8.
#475
merging of similar tickets
#519
Python process sometimes hangs on Windows Server 2003
#529
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.

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 using the count parameter.

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

This is displayed as:

10

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:

[[TicketQuery(max=3,status=closed,order=id,desc=1,format=table,col=resolution|summary|owner|reporter)]]

This is displayed as:

Full rows

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

[[TicketQuery(max=3,status=closed,order=id,desc=1,format=table,col=resolution|summary|owner|reporter,rows=description)]]

This is displayed as:

Results (1 - 3 of 11310)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#13867 fixed Unit tests failing with Subversion 1.14.5 Jun Omae Jun Omae
Description

It seems that SubversionNode.get_copy_ancestry raises the following AttributeError in the all failures.

======================================================================
ERROR: test_get_copy_ancestry_for_move (tracopt.versioncontrol.svn.tests.svn_fs.SvnCachedRepositoryScopedTests.test_get_copy_ancestry_for_move)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/runner/work/trac/trac/tracopt/versioncontrol/svn/tests/svn_fs.py", line 1267, in test_get_copy_ancestry_for_move
    ancestry = node.get_copy_ancestry()
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/runner/work/trac/trac/tracopt/versioncontrol/svn/svn_fs.py", line 855, in get_copy_ancestry
    path = path.lstrip(b'/')
           ^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'lstrip'

...
Ran 2810 tests in 554.016s

FAILED (errors=12, skipped=5)
#13866 fixed Syntax hightlihging has unexpected styles after Pygments 2.7.0 Jun Omae Jun Omae
Description

After Pygments 2.7.0, the syntax highlighting has unexpected styles (e.g. pre, td.linenoes pre).

$ script='import pygments; from pygments.formatters.html import HtmlFormatter as F; print(pygments.__version__); print(F().get_style_defs("div.code pre"))'
$ diff -u <(/venv/pygments-2.6.1/bin/python -c "$script") \
>         <(/venv/pygments-2.7.0/bin/python -c "$script")
--- /dev/fd/63  2025-02-05 19:05:33.783629775 +0900
+++ /dev/fd/62  2025-02-05 19:05:33.783629775 +0900
@@ -1,6 +1,11 @@
-2.6.1
+2.7.0
+pre { line-height: 125%; margin: 0; }
+td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
+span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
+td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
+span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
 div.code pre .hll { background-color: #ffffcc }
-div.code pre  { background: #f8f8f8; }
+div.code pre { background: #f8f8f8; }
 div.code pre .c { color: #408080; font-style: italic } /* Comment */
 div.code pre .err { border: 1px solid #FF0000 } /* Error */
 div.code pre .k { color: #008000; font-weight: bold } /* Keyword */

I think we could directly invoke get_background_style_defs and get_token_style_defs in the HtmlFormatter.

  • trac/mimeview/pygments.py

     
    3737__all__ = ['PygmentsRenderer']
    3838
    3939
     40if hasattr(HtmlFormatter, 'get_background_style_defs') and \
     41        hasattr(HtmlFormatter, 'get_token_style_defs'):
     42    def _get_style_defs(style, arg):  # Pygments 2.7.0+
     43        lines = []
     44        formatter = HtmlFormatter(style=style)
     45        lines.extend(formatter.get_background_style_defs(arg))
     46        lines.extend(formatter.get_token_style_defs(arg))
     47        return '\n'.join(lines)
     48else:
     49    def _get_style_defs(style, arg):
     50        formatter = HtmlFormatter(style=style)
     51        return formatter.get_style_defs(arg)
     52
     53
    4054class PygmentsRenderer(Component):
    4155    """HTML renderer for syntax highlighting based on Pygments."""
    4256
     
    186200            req.end_headers()
    187201            return
    188202
    189         formatter = HtmlFormatter(style=style_cls)
    190         content = formatter.get_style_defs(['div.code pre', 'table.code td'])
     203        content = _get_style_defs(style_cls, ['div.code pre', 'table.code td'])
    191204        content = content.encode('utf-8')
    192205
    193206        req.send_response(200)

See also: https://github.com/pygments/pygments/blob/2.19.1/pygments/formatters/html.py#L516

#13865 fixed 2 test failures with Pygments 2.19.0 or later Jun Omae Jun Omae
Description
======================================================================
FAIL: test_python_hello (trac.mimeview.tests.pygments.PygmentsRendererTestCase.test_python_hello)
Simple Python highlighting with Pygments (direct)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/tracdev/git/trac/mimeview/tests/pygments.py", line 92, in test_python_hello
    self._test('python_hello_pygments_2.1plus', result)
  File "/home/jun66j5/src/tracdev/git/trac/mimeview/tests/pygments.py", line 76, in _test
    self.assertEqual(split(exp), split(res))
AssertionError: Lists differ: ['<sp[26 chars]>', ' <span class="nf">', 'hello</span>', '<sp[24 chars]an>'] != ['<sp[26 chars]>', '<span class="w">', ' </span>', '<span cla[55 chars]an>']

First differing element 2:
' <span class="nf">'
'<span class="w">'

Second list contains 2 additional elements.
First extra element 6:
'<span class="p">'

  ['<span class="k">',
   'def</span>',
+  '<span class="w">',
+  ' </span>',
-  ' <span class="nf">',
?   -

+  '<span class="nf">',
   'hello</span>',
   '<span class="p">',
   '():</span>']

======================================================================
FAIL: test_python_hello_mimeview (trac.mimeview.tests.pygments.PygmentsRendererTestCase.test_python_hello_mimeview)
Simple Python highlighting with Pygments (through Mimeview.render)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/jun66j5/src/tracdev/git/trac/mimeview/tests/pygments.py", line 107, in test_python_hello_mimeview
    self._test('python_hello_mimeview_pygments_2.1plus', result)
  File "/home/jun66j5/src/tracdev/git/trac/mimeview/tests/pygments.py", line 76, in _test
    self.assertEqual(split(exp), split(res))
AssertionError: Lists differ: ['<sp[26 chars]>', ' <span class="nf">', 'hello</span>', '<sp[24 chars]an>'] != ['<sp[26 chars]>', '<span class="w">', ' </span>', '<span cla[55 chars]an>']

First differing element 2:
' <span class="nf">'
'<span class="w">'

Second list contains 2 additional elements.
First extra element 6:
'<span class="p">'

  ['<span class="k">',
   'def</span>',
+  '<span class="w">',
+  ' </span>',
-  ' <span class="nf">',
?   -

+  '<span class="nf">',
   'hello</span>',
   '<span class="p">',
   '():</span>']

----------------------------------------------------------------------
Ran 2810 tests in 30.870s

FAILED (failures=2, skipped=5)
make: *** [Makefile:477: unit-test] Error 1
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.

The available operators are:

= the field content exactly matches the 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

See also: TracTickets, TracReports, TracGuide

Last modified 15 years ago Last modified on Apr 10, 2010, 6:37:10 PM
Note: See TracWiki for help on using the wiki.