wiki:TracQuery

Trac Ticket Queries

In addition to reports, Trac provides support for custom ticket queries, which can be used to display tickets that meet specified 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 in and no name/email is 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 on 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.

After you have edited your filters, click the Update button to refresh your results.

Some shortcuts can be used to manipulate checkbox filters.

  • Clicking on a filter row label toggles all checkboxes.
  • Pressing the modifier key while clicking on a filter row label inverts the state of all checkboxes.
  • Pressing the modifier key while clicking on a checkbox selects the checkbox and deselects all other checkboxes in the filter.

The modifier key is platform and browser dependent. On Mac the modified key is Option/Alt or Command. On Linux the modifier key is Ctrl + Alt. Opera on Windows seems to use Ctrl + Alt, while Alt is effective for other Windows browsers.

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

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 in by placing pipes (|) between the columns:

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

This is displayed as:

Results (1 - 3 of 125)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#146 wontfix Allow to trust pasv sent from server in session_factory schwa ftputiluser
#145 fixed ftputil 5.0.0: kwargs not being passed through to ftplib.FTP schwa ftputiluser
#143 fixed Encoding-related failure with Python 3.9 schwa schwa
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>:

[[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 125)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#146 wontfix Allow to trust pasv sent from server in session_factory schwa ftputiluser
Description

Hello,

Python recently made the ftplib not trusting the PASV response sent from the server by default : https://github.com/python/cpython/commit/79373951b3eab585d42e0f0ab83718cbe1d0ee33

This means that if we rely on the IP sent back by the server, we need to set trust_server_pasv_ipv4_address to True.

When using ftputil, it means that we have to create a subclass specifically for this, as for now the option is not available in the session_factory.

Working code : ` import ftplib

class FTPTrustPASV(ftplib.FTP_TLS):

def init(self, host, userid, password, port, debug_level: int = 0):

"""Act like ftplib.FTP's constructor but force trusting the pasv from the server.""" super().init() self.trust_server_pasv_ipv4_address = True self.connect(host, port) self.login(userid, password) self.prot_p() self.debug_level = debug_level

`

Being able to set trust_server_pasv_ipv4_address from the session_factory, without having to create a whole new subclass, would be pretty nice.

#145 fixed ftputil 5.0.0: kwargs not being passed through to ftplib.FTP schwa ftputiluser
Description

We specify timeout as a kwarg to the ftputil.FTPHost constructor for passthrough to ftplib.FTP, which worked through ftputil 4.0.0. However, in 5.0.0 the constructor of ftputil.session.Session does not support the other kwargs passed to ftplib.FTP-- it only supports host, user and password. As a result any code relying on the acct, timeout, or source_address kwargs breaks. I believe the solution is just to add **kwargs to the Session.__init__ method and pass them through the super.__init__ method.

Stack trace:

In [11]: host = ftputil.FTPHost(creds['host'], creds['user'], creds['pwd'], timeout=10)
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-9308d6c2abeb> in <module>
----> 1 host = ftputil.FTPHost(creds['host'], creds['user'], creds['pwd'], timeout=10)

C:\Miniconda3\envs\test_feb_2021\lib\site-packages\ftputil\host.py in __init__(self, *args, **kwargs)
     82         # The time shift setting shouldn't be reset though. Make a session
     83         # according to these arguments.
---> 84         self._session = self._make_session()
     85         # Simulate `os.path`.
     86         self.path = ftputil.path._Path(self)

C:\Miniconda3\envs\test_feb_2021\lib\site-packages\ftputil\host.py in _make_session(self)
    149                     f"session instance {session!r} must have an `encoding` attribute"
    150                 )
--> 151             self._encoding = session.encoding
    152         return session
    153

C:\Miniconda3\envs\test_feb_2021\lib\site-packages\ftputil\host.py in _make_session(self)
    144         factory = kwargs.pop("session_factory", default_session_factory)
    145         with ftputil.error.ftplib_error_to_ftp_os_error:
--> 146             session = factory(*args, **kwargs)
    147             if not hasattr(session, "encoding"):
    148                 raise ftputil.error.NoEncodingError(

TypeError: __init__() got an unexpected keyword argument 'timeout'
#143 fixed Encoding-related failure with Python 3.9 schwa schwa
Description

When running the tests with tox for Python 3.9, I get

______________ TestOther.test_listdir_with_non_ascii_byte_string _______________
test/test_real_ftp.py:895: in test_listdir_with_non_ascii_byte_string
    names = host.listdir(path)
ftputil/host.py:906: in listdir
    items = self._stat._listdir(path)
ftputil/stat.py:825: in _listdir
    return self.__call_with_parser_retry(self._real_listdir, path)
ftputil/stat.py:801: in __call_with_parser_retry
    result = method(*args, **kwargs)
ftputil/stat.py:681: in _real_listdir
    raise ftputil.error.PermanentError(
E   ftputil.error.PermanentError: 550 /äbc: no such directory or wrong directory parser used
E   Debugging info: ftputil 4.0.0, Python 3.9.0 (linux)
_____________ TestOther.test_listdir_with_non_ascii_unicode_string _____________
test/test_real_ftp.py:908: in test_listdir_with_non_ascii_unicode_string
    names = host.listdir(path)
ftputil/host.py:906: in listdir
    items = self._stat._listdir(path)
ftputil/stat.py:825: in _listdir
    return self.__call_with_parser_retry(self._real_listdir, path)
ftputil/stat.py:801: in __call_with_parser_retry
    result = method(*args, **kwargs)
ftputil/stat.py:681: in _real_listdir
    raise ftputil.error.PermanentError(
E   ftputil.error.PermanentError: 550 /äbc: no such directory or wrong directory parser used
E   Debugging info: ftputil 4.0.0, Python 3.9.0 (linux)
______________ TestOther.test_path_with_non_latin1_unicode_string ______________
test/test_real_ftp.py:922: in test_path_with_non_latin1_unicode_string
    self.host.mkdir(path)
E   Failed: DID NOT RAISE <class 'UnicodeEncodeError'>
=========================== short test summary info ============================
FAILED test/test_real_ftp.py::TestOther::test_listdir_with_non_ascii_byte_string
FAILED test/test_real_ftp.py::TestOther::test_listdir_with_non_ascii_unicode_string
FAILED test/test_real_ftp.py::TestOther::test_path_with_non_latin1_unicode_string
================== 3 failed, 182 passed in 185.52s (0:03:05) ===================
ERROR: InvocationError for command /home/build/ftputil/.tox/py39/bin/python -m pytest test (exited with code 1)
___________________________________ summary ____________________________________
  py36: commands succeeded
  py37: commands succeeded
  py38: commands succeeded
ERROR:   py39: commands failed

I assume this is related to https://docs.python.org/3/whatsnew/3.9.html#changes-in-the-python-api :

The encoding parameter has been added to the classes ftplib.FTP and ftplib.FTP_TLS as a keyword-only parameter, and the default encoding is changed from Latin-1 to UTF-8 to follow RFC 2640.

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. Filters are separated by ampersands (&). Each filter 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 omitted 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, TicketQuery

Last modified 2 years ago Last modified on Apr 21, 2019, 6:07:41 PM