Version 6 (modified by trac, 6 years ago) (diff)


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

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:

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.

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 using 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:

Results (1 - 3 of 25417)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#27366 invalid KeyError: 'no_color' in, l. 314 nobody Geoffrey R.
#27365 needsinfo Fields suddenly not found. nobody Brandon
#27364 invalid DATE_INPUT_FORMATS is not working nobody Alex
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:


This is displayed as:

Results (1 - 3 of 25417)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#27366 invalid KeyError: 'no_color' in, l. 314 nobody Geoffrey R.


I played with Django Mezzanine and when creating the database with the following settings:



    ('en', _('English')),
    ('fr', _('French'))

and executing

python createdb

as mentionned on mezzanine's website, I get the following Traceback after having provided my login / email / pwd and saying that I want to translate fields:

Django-modeltranslation is installed for this project and you have specified to use i18n.
Would you like to update translation fields from the default ones? (yes/no): yes
Traceback (most recent call last):
  File "", line 14, in <module>
  File "/home/ge0/envs/bakadeshi/lib/python3.5/site-packages/django/core/management/", line 367, in execute_from_command_line
  File "/home/ge0/envs/bakadeshi/lib/python3.5/site-packages/django/core/management/", line 359, in execute
  File "/home/ge0/envs/bakadeshi/lib/python3.5/site-packages/django/core/management/", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ge0/envs/bakadeshi/lib/python3.5/site-packages/django/core/management/", line 345, in execute
    output = self.handle(*args, **options)
  File "/home/ge0/envs/bakadeshi/lib/python3.5/site-packages/mezzanine/core/management/commands/", line 61, in handle
  File "/home/ge0/envs/bakadeshi/lib/python3.5/site-packages/mezzanine/core/management/commands/", line 151, in translation_fields
    verbosity=self.verbosity, interactive=False)
  File "/home/ge0/envs/bakadeshi/lib/python3.5/site-packages/django/core/management/", line 314, in execute
    if options['no_color']:
KeyError: 'no_color'

Python version: 3.5.2

Installed packages:

#27365 needsinfo Fields suddenly not found. nobody Brandon

Hello, We just moved from Django 1.7.10 to 1.9.9. After the move a new error began occurring. The exception is: FieldDoesNotExist: No related field named '...'

We see the exception when accessing the reverse OneToOne of a non-abstract models.Model subclass that has been subclassed.

class Case(models.Model):
   ...lots of fields...
class SubclassCase(Case):
  ...lots more fields...

generates traceback

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/", line 149, in get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/", line 147, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/", line 23, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "/var/www/vhosts/prod/lib/workpath/workflow/", line 1730, in view_case
    additional_view = case_module.view(case)
  File "/var/www/vhosts/prod/lib/workpath/workflow/cases/subclasscase/", line 286, in view
    case = SubclassCase.objects.get(
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", line 122, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", line 378, in get
    clone = self.filter(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", line 790, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/", line 808, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/", line 1243, in add_q
    clause, _ = self._add_q(q_object, self.used_aliases)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/", line 1269, in _add_q
    allow_joins=allow_joins, split_subq=split_subq,
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/", line 1149, in build_filter
    lookups, parts, reffed_expression = self.solve_lookup_type(arg)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/", line 1035, in solve_lookup_type
    _, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/", line 1345, in names_to_path
    targets = (final_field.remote_field.get_related_field(),)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/fields/", line 244, in get_related_field
FieldDoesNotExist: No related field named 'subclasscase'

Whenever the exception occurs, it is exactly this exception every time once _filter_or_exclude is reached. We've seen it in the context of function based views, class based views, the views of our tastypie backed API (XML and JSON) and from view functions that support light-weight JSON functions. We see it across multiple disconnected deployments with completely separate machines, datastores, databases, etc. We do not see it all the time. We do not see it when running under the development server. An apache restart fixes it... for a little while.

We are using mpm_event with WSGI. Our mpm_event configuration looks like this:

<IfModule mpm_event_module>
        StartServers               2
        MinSpareThreads           25
        MaxSpareThreads           75
        ThreadLimit               64
        ThreadsPerChild           25
        MaxRequestWorkers        150
        MaxConnectionsPerChild  5000

Our WSGI (libapache2-mod-wsgi 3.4-4ubuntu2. configuration looks like this:

WSGIDaemonProcess prod processes=2 python-path=/usr/local/lib/python2.7/dist-packages:/var/www/vhosts/prod/lib

Based on our experience that an apache restart fixed it we changed our WSGI configuration to this:

WSGIDaemonProcess prod processes=10 threads=1 maximum-requests=50 python-path=/usr/local/lib/python2.7/dist-packages:/var/www/vhosts/prod/lib

This causes the apache children to cycle quickly and the error goes away but as you can imagine this slows down the site considerably.

The error occurs much more frequently with 1.8.15 than with 1.9.9 - but again it *never* occurred in 1.7.10. Based on this, and looking at git diff 1.7.10...1.9.9 -- django/db/models/; I believe it is somehow related to the _meta API change and the introduction of _get_fields_cache in the Options class.

However, I am very unfamiliar with core django code... so that could be completely wrong.

The real difficulty here is that it seems to be time or number-of-requests based. A apache child, immediately after a restart, hums along nicely. But it *seems* that if any particular code path that needs to do that kind of "reverse OneToOne" lookup is crossed too many times the error, that exact exception, occurs. Once it has occurred for a child, that child is done. If you access the site and get that child looking for that object, the exception occurs. But if you get another apache child or are looking for another object, the error has a good chance of not occurring. Again, if that child cycles out or if Apache is restarted (not reloaded) the error vanishes completely... for a little while, seemingly dependent on site traffic.

I'll be glad to supply any debug information I can. As pervasive as this error was in production, I have been unable to reproduce the problem in a development environment. As soon as I have, I'll update the ticket with whatever information I've found.

Any insight anyone could provide in debugging this problem would be much appreciated. I would not hesitate to submit a patch if I had one.

Thanks, --Brandon

#27364 invalid DATE_INPUT_FORMATS is not working nobody Alex

Per the Django Docs, in if I set USE_L10N to false, I should be able to override the supported date formats. My has the following:



USE_I18N = False

USE_L10N = False

USE_TZ = False

    '%Y-%m-%d', '%m/%d/%Y', '%m/%d/%y', # '2006-10-25', '10/25/2006', '10/25/06'
    '%b %d %Y', '%b %d, %Y',            # 'Oct 25 2006', 'Oct 25, 2006'
    '%d %b %Y', '%d %b, %Y',            # '25 Oct 2006', '25 Oct, 2006'
    '%B %d %Y', '%B %d, %Y',            # 'October 25 2006', 'October 25, 2006'
    '%d %B %Y', '%d %B, %Y',            # '25 October 2006', '25 October, 2006'

I have a model that looks like the following:

class DateTest(models.Model):
    date = models.DateField(blank=True, null=True)

When I run the following command, i get an error:

>>> DateTest.objects.create(date='09/01/2016')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 399, in create, using=self.db)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 796, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 824, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 908, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 947, in _do_insert
    using=using, raw=raw)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/", line 1045, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/", line 1053, in execute_sql
    for sql, params in self.as_sql():
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/", line 1006, in as_sql
    for obj in self.query.objs
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/", line 1006, in <listcomp>
    for obj in self.query.objs
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/", line 1005, in <listcomp>
    [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields]
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/sql/", line 945, in prepare_value
    value = field.get_db_prep_save(value, connection=self.connection)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/", line 755, in get_db_prep_save
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/", line 1280, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/", line 1275, in get_prep_value
    return self.to_python(value)
  File "/Users/abeach/Workspace/orchard/env/lib/python3.5/site-packages/django/db/models/fields/", line 1250, in to_python
    params={'value': value},
django.core.exceptions.ValidationError: ["'09/01/2016' value has an invalid date format. It must be in YYYY-MM-DD format."]

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 litteral & or | in a value, escape the character with a backslash (\).

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

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

Back to Top