wiki:TracQuery
Last modified 9 years ago Last modified on 08/29/13 12:47:07

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 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.

Example:

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

This is displayed as:

No results

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:

[[TicketQuery(id=123)]]

This is displayed as:

#123
savannah: 2GB file size limit in fish

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

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

This is displayed as:

No results

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:

0

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:

Results (1 - 3 of 2570)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#4406 duplicate Internal viewer does not navigate to the precise search "found" point al12345
#4403 duplicate opening zip archive with pdf as a first file fails durdin
#4401 fixed Segmentation fault in mc viewer (growbuf.c) andrew_b misch
1 2 3 4 5 6 7 8 9 10 11

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 2570)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#4406 duplicate Internal viewer does not navigate to the precise search "found" point al12345
Description

In internal viewer (mcview): When viewing a text file with quite long lines, not fitting in a single screen, search for a fragment does not navigate to the found fragment point, but rather displays a beginning of the line.

Attached is a file "test.txt" containing 3 long lines: 1) Line 1 ..............<many '.'s>...12345678.......<many '.'s>..... 2) Line 2 --------------<many '-'s>---12345678-------<many '-'s>----- 3) Line 3 ==============<many '='s>===12345678=======<many '-'s>=====

When viewing in the wrapped or unwrapped modes, and searching for 12345678, search results are displayed as beginnings of the lines 1, 2 and 3, instead of being navigated to the "12345678" fragments - see attached Screenchot_N.png files.

#4403 duplicate opening zip archive with pdf as a first file fails durdin
Description

I've first faced it with Intel NUC 10 BIOS zip file (either UEFI or Recorvery version) from https://www.intel.com/content/www/us/en/download/19485/bios-update-fncml357.html, but as tested it happens with any zip file which has first entry as a PDF.

When you try to open it in MC (by hitting Enter on it) and when in X-session it opens the system archiver, hitting "enter" on the file in base terminal without X-session attempts to parse the zip via some console pdf viewer but obviously fails with:

Syntax Warning: May not be a PDF file (continuing anyway)
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't find trailer dictionary
Syntax Error: Couldn't read xref table

Trying to view the zip via the "F3" results in an error: Syntax Warning: May not be a PDF file (continuing anyway), but nothing happens.

MC version (running on debian):

$ LANG=C mc -V
GNU Midnight Commander 4.8.28
Built with GLib 2.72.0
Built with S-Lang 2.3.2 with terminfo database
Built with libssh2 1.10.0
With builtin Editor and Aspell support
With subshell support as default
With support for background operations
With mouse support on xterm and Linux console
With support for X11 events
With internationalization support
With multiple codepages support
With ext2fs attributes support
Virtual File Systems:
 cpiofs, tarfs, sfs, extfs, ext2undelfs, ftpfs, sftpfs, fish
Data types:
 char: 8; int: 32; long: 64; void *: 64; size_t: 64; off_t: 64;

$ LANG=C mc -F
[System data]
    Config directory: /etc/mc/
    Data directory:   /usr/share/mc/
    File extension handlers: /usr/lib/mc/ext.d/
    VFS plugins and scripts: /usr/lib/mc/
	extfs.d:        /usr/lib/mc/extfs.d/
	fish:           /usr/lib/mc/fish/

$ mc --configure-options
 '--build=x86_64-linux-gnu' '--prefix=/usr' '--includedir=${prefix}/include' '--mandir=${prefix}/share/man' '--infodir=${prefix}/share/info' '--sysconfdir=/etc' '--localstatedir=/var' '--disable-option-checking' '--libdir=${prefix}/lib/x86_64-linux-gnu' '--runstatedir=/run' '--disable-maintainer-mode' '--disable-dependency-tracking' 'AWK=awk' 'X11_WWW=x-www-browser' '--libexecdir=/usr/lib' '--with-x' '--with-screen=slang' '--disable-rpath' '--disable-static' '--disable-silent-rules' '--enable-aspell' '--enable-vfs-sftp' '--enable-vfs-undelfs' '--enable-tests' 'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -ffile-prefix-map=/build/mc-rb7yno/mc-4.8.28=. -fstack-protector-strong -Wformat -Werror=format-security' 'LDFLAGS=-Wl,-z,relro -Wl,-z,now -Wl,--as-needed' 'CPPFLAGS=-Wdate-time -D_FORTIFY_SOURCE=2'

Archive used:

$ zipinfo FNCML357.0057.UEFI.zip 
Archive:  FNCML357.0057.UEFI.zip
Zip file size: 11594357 bytes, number of entries: 3
-rw-a--     2.0 fat   739251 bx defX 21-Jan-29 14:18 iFlashV-User-Guide-V3.0.pdf
-rw-a--     2.0 fat   418448 bx defX 22-Mar-31 01:32 iFlashVEfi64.efi
-rw-a--     2.0 fat 20971520 bx defX 22-May-20 03:46 FN0057.cap
3 files, 22129219 bytes uncompressed, 11593893 bytes compressed:  47.6%
#4401 fixed Segmentation fault in mc viewer (growbuf.c) andrew_b misch
Description

The viewer crashes while viewing ELF binaries with hidden symbols, when switching from parse to raw mode and back. The parsed content is coming from nm via stdio pipe.

Steps to reproduce:

  1. Open binary without symbols in the viewer: mcview /usr/bin/ls
  2. Switch from parse to raw mode and back.

Debugging revealed that the crash is caused by double-closing the pipe:

  1. In src/viewer/growbuf.c:188 the output from nm is shown by mcview_show_error
  2. view->ds_stdio_pipe now suddenly is set to NULL, leaving sp invalid
  3. Line 213: mcview_growbuf_done (view); leads to:
  4. Line 82: which crashes in mc_pclose(NULL, NULL)

I suspect freeing resources down the messaging system triggers a second call to mcview_close_datasource -> mcview_growbuf_done.

As a working patch attached to this ticket I suggest to reintroduce the check that was removed by ticket #4103 (mc-4103-cid-growbuf.c-fix-dereference-before-null-check.patch) while taking sp's invalidity into account and to implement a NULL pointer check in mc_pclose as well.

Tested on 64-bit Ubuntu Linux and on ARMv7 Raspbian 10 (buster) which I also used for building and debugging MC, starting with the distro source package & build deps for MC 4.8.22. On Raspbian 11 (bullseye) the crash could be reproduced with MC 4.8.26. Afterwards I built and debugged the latest master from Git (commit 08cca8aae8c2f36e26ff99174f5cc40e551a98ab).

Version output:

# LC_MESSAGES=C src/mc -V

GNU Midnight Commander 4.8.28-86-g08cca8aae
Built with GLib 2.58.3
Built with S-Lang 2.3.2 with terminfo database
Built with libssh2 1.8.0
With builtin Editor and Aspell support
With subshell support as default
With support for background operations
With mouse support on xterm and Linux console
With support for X11 events
With internationalization support
With multiple codepages support
With ext2fs attributes support
Virtual File Systems:
 cpiofs, tarfs, sfs, extfs, ext2undelfs, ftpfs, sftpfs, fish
Data types:
 char: 8; int: 32; long: 32; void *: 32; size_t: 32; off_t: 64;

# LC_MESSAGES=C mc -F

Home directory: /home/pi
Profile root directory: /home/pi

[System data]
    Config directory: /etc/mc/
    Data directory:   /usr/share/mc/
    File extension handlers: /usr/lib/mc/ext.d/
    VFS plugins and scripts: /usr/lib/mc/
	extfs.d:        /usr/lib/mc/extfs.d/
	fish:           /usr/lib/mc/fish/

[User data]
    Config directory: /home/pi/.config/mc/
    Data directory:   /home/pi/.local/share/mc/
	skins:          /home/pi/.local/share/mc/skins/
	extfs.d:        /home/pi/.local/share/mc/extfs.d/
	fish:           /home/pi/.local/share/mc/fish/
	mcedit macros:  /home/pi/.local/share/mc/mc.macros
	mcedit external macros: /home/pi/.local/share/mc/mcedit/macros.d/macro.*
    Cache directory:  /home/pi/.cache/mc/

# mc --configure-options

'--build=arm-linux-gnueabihf'
'--prefix=/usr'
'--includedir=/usr/include'
'--mandir=/usr/share/man'
'--infodir=/usr/share/info'
'--sysconfdir=/etc'
'--localstatedir=/var'
'--disable-option-checking'
'--libdir=/usr/lib/arm-linux-gnueabihf'
'--libexecdir=/usr/lib/arm-linux-gnueabihf'
'--disable-maintainer-mode'
'--disable-dependency-tracking'
'AWK=awk'
'X11_WWW=x-www-browser'
'--libexecdir=/usr/lib'
'--with-x'
'--with-screen=slang'
'--disable-rpath'
'--disable-static'
'--disable-silent-rules'
'--enable-aspell'
'--enable-vfs-sftp'
'--enable-vfs-undelfs'
'build_alias=arm-linux-gnueabihf'

gdb Backtrace:

#0  0x000d8708 in mc_pclose (p=0x0, error=0x0) at utilunix.c:678
#1  0x000d1be0 in mcview_growbuf_done (view=0x226338) at growbuf.c:82
#2  0x000d2074 in mcview_growbuf_read_until (view=0x226338, ofs=1) at growbuf.c:213
#3  0x000d23d0 in mcview_get_ptr_growing_buffer (view=0x226338, byte_index=0) at growbuf.c:279
#4  0x000d2224 in mcview_get_byte_growing_buffer (view=0x226338, byte_index=0, retval=0x0) at growbuf.c:254
#5  0x000cf420 in mcview_get_byte (view=0x226338, offset=0, retval=0x0) at internal.h:399
#6  0x000cffbc in mcview_load_command_output (view=0x226338, command=0x2272d8 "/bin/sh /tmp/mc-pi/mcextJFYTQ1")
    at datasource.c:399
#7  0x000662cc in mcview_load (view=0x226338, command=0x2272d8 "/bin/sh /tmp/mc-pi/mcextJFYTQ1", 
    file=0x221d90 "/usr/bin/ls", start_line=0, search_start=0, search_end=0) at mcviewer.c:325
#8  0x00064af4 in mcview_toggle_magic_mode (view=0x226338) at lib.c:90
#9  0x000cbbbc in mcview_execute_cmd (view=0x226338, command=601) at actions_cmd.c:489
#10 0x000cc344 in mcview_callback (w=0x226338, sender=0x226588, msg=MSG_ACTION, parm=601, data=0x0)
    at actions_cmd.c:704
#11 0x00108e9c in send_message (w=0x226338, sender=0x226588, msg=MSG_ACTION, parm=601, data=0x0)
    at ../../lib/widget/widget-common.h:255
#12 0x00109358 in buttonbar_call (bb=0x226588, i=7) at buttonbar.c:154
#13 0x001093f0 in buttonbar_callback (w=0x226588, sender=0x0, msg=MSG_HOTKEY, parm=1008, data=0x0)
    at buttonbar.c:171
#14 0x0010c9c8 in send_message (w=0x226588, sender=0x0, msg=MSG_HOTKEY, parm=1008, data=0x0)
    at ../../lib/widget/widget-common.h:255
#15 0x0010dc54 in group_handle_hotkey (g=0x2254a0, key=1008) at group.c:564
#16 0x0010dec4 in group_default_callback (w=0x2254a0, sender=0x0, msg=MSG_HOTKEY, parm=1008, data=0x0)
    at group.c:638
#17 0x0010b4cc in dlg_default_callback (w=0x2254a0, sender=0x0, msg=MSG_HOTKEY, parm=1008, data=0x0)
    at dialog.c:368
#18 0x000cc538 in mcview_dialog_callback (w=0x2254a0, sender=0x0, msg=MSG_HOTKEY, parm=1008, data=0x0)
    at actions_cmd.c:785
#19 0x0010c9c8 in send_message (w=0x2254a0, sender=0x0, msg=MSG_HOTKEY, parm=1008, data=0x0)
    at ../../lib/widget/widget-common.h:255
#20 0x0010d9e0 in group_handle_key (g=0x2254a0, key=1008) at group.c:501
#21 0x0010deb0 in group_default_callback (w=0x2254a0, sender=0x0, msg=MSG_KEY, parm=1008, data=0x0) at group.c:635
#22 0x0010b4cc in dlg_default_callback (w=0x2254a0, sender=0x0, msg=MSG_KEY, parm=1008, data=0x0) at dialog.c:368
#23 0x000cc538 in mcview_dialog_callback (w=0x2254a0, sender=0x0, msg=MSG_KEY, parm=1008, data=0x0)
    at actions_cmd.c:785
#24 0x0010aae4 in send_message (w=0x2254a0, sender=0x0, msg=MSG_KEY, parm=1008, data=0x0)
    at ../../lib/widget/widget-common.h:255
#25 0x0010b120 in dlg_key_event (h=0x2254a0, d_key=1008) at dialog.c:248
#26 0x0010bd30 in dlg_process_event (h=0x2254a0, key=1008, event=0x7effee3c) at dialog.c:568
#27 0x0010b36c in frontend_dlg_run (h=0x2254a0) at dialog.c:320
#28 0x0010be30 in dlg_run (h=0x2254a0) at dialog.c:602
#29 0x000660bc in mcview_viewer (command=0x2071f0 "/bin/sh /tmp/mc-pi/mcextJFYTQ1", file_vpath=0x1ef460, 
    start_line=0, search_start=0, search_end=0) at mcviewer.c:266
#30 0x000260ec in exec_extension_view (target=0x0, cmd=0x2071f0 "/bin/sh /tmp/mc-pi/mcextJFYTQ1", 
    filename_vpath=0x1ef460, start_line=0) at ext.c:384
#31 0x00026630 in exec_extension (panel=0x1e7680, target=0x0, filename_vpath=0x1ef460, 
    lc_data=0x20d255 "%view{ascii} /usr/lib/mc/ext.d/misc.sh view elf\n\n### Documentation ###\n\n# Texinfo\n#regex/\\.(te?xi|texinfo)$\n\n# GNU Info page\ntype/^Info\\ text\n \tOpen=/usr/lib/mc/ext.d/text.sh open info\n\nshell/.info\n\tO"..., start_line=0) at ext.c:512
#32 0x000278d0 in regex_command_for (target=0x0, filename_vpath=0x1ef460, action=0x7efff094 "View", 
    script_vpath=0x0) at ext.c:1043
#33 0x000af380 in regex_command (filename_vpath=0x1ef460, action=0x7efff094 "View") at ext.h:30
#34 0x000b039c in view_file_at_line (filename_vpath=0x1ef460, plain_view=0, internal=1, start_line=0, 
    search_start=0, search_end=0) at cmd.c:532
#35 0x000b0528 in view_file (filename_vpath=0x1ef460, plain_view=0, internal=1) at cmd.c:571
#36 0x000af578 in do_view_cmd (panel=0x1e7680, plain_view=0) at cmd.c:153
#37 0x000b0554 in view_cmd (panel=0x1e7680) at cmd.c:581
#38 0x0002ecac in midnight_execute_cmd (sender=0x2024b8, command=101) at filemanager.c:1414
#39 0x0002f4a4 in midnight_callback (w=0x1ec8d8, sender=0x2024b8, msg=MSG_ACTION, parm=101, data=0x0)
    at filemanager.c:1609
#40 0x00108e9c in send_message (w=0x1ec8d8, sender=0x2024b8, msg=MSG_ACTION, parm=101, data=0x0)
    at ../../lib/widget/widget-common.h:255
#41 0x00109358 in buttonbar_call (bb=0x2024b8, i=2) at buttonbar.c:154
#42 0x001093f0 in buttonbar_callback (w=0x2024b8, sender=0x0, msg=MSG_HOTKEY, parm=1003, data=0x0)
    at buttonbar.c:171
#43 0x0010c9c8 in send_message (w=0x2024b8, sender=0x0, msg=MSG_HOTKEY, parm=1003, data=0x0)
    at ../../lib/widget/widget-common.h:255
#44 0x0010dc54 in group_handle_hotkey (g=0x1ec8d8, key=1003) at group.c:564
#45 0x0010dec4 in group_default_callback (w=0x1ec8d8, sender=0x0, msg=MSG_HOTKEY, parm=1003, data=0x0)
    at group.c:638
#46 0x0010b4cc in dlg_default_callback (w=0x1ec8d8, sender=0x0, msg=MSG_HOTKEY, parm=1003, data=0x0)
    at dialog.c:368
#47 0x0002f4d4 in midnight_callback (w=0x1ec8d8, sender=0x0, msg=MSG_HOTKEY, parm=1003, data=0x0)
    at filemanager.c:1616
#48 0x0010c9c8 in send_message (w=0x1ec8d8, sender=0x0, msg=MSG_HOTKEY, parm=1003, data=0x0)
    at ../../lib/widget/widget-common.h:255
#49 0x0010d9e0 in group_handle_key (g=0x1ec8d8, key=1003) at group.c:501
#50 0x0010deb0 in group_default_callback (w=0x1ec8d8, sender=0x0, msg=MSG_KEY, parm=1003, data=0x0) at group.c:635
#51 0x0010b14c in dlg_key_event (h=0x1ec8d8, d_key=1003) at dialog.c:251
#52 0x0010bd30 in dlg_process_event (h=0x1ec8d8, key=1003, event=0x7efff40c) at dialog.c:568
#53 0x0010b36c in frontend_dlg_run (h=0x1ec8d8) at dialog.c:320
#54 0x0010be30 in dlg_run (h=0x1ec8d8) at dialog.c:602
#55 0x0002feb0 in do_nc () at filemanager.c:1827
#56 0x00019458 in main (argc=2, argv=0x7efff624) at main.c:455
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