Version 6 (modified by trac, 7 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:

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

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#28503 invalid Updating 1.10 to 1.11 object has no attribute 'select_for_update_skip_locked' nobody Jorge Cadena Argote

I upgrade from version 1.10.7 to 1.11.4 and I get the following error.

AttributeError: 'Query' object has no attribute 'select_for_update_skip_locked'

(env) aztrock@debian:~/workspace/env/kibox$ python runserver
Performing system checks...

/home/aztrock/workspace/env/local/lib/python3.5/site-packages/redis_cache/ RuntimeWarning: Pickled model instance's Django version 1.10.6 does not match the current version 1.11.4.
  return pickle.loads(force_bytes(value))
/home/aztrock/workspace/env/local/lib/python3.5/site-packages/redis_cache/ RuntimeWarning: Pickled queryset instance's Django version 1.10.6 does not match the current version 1.11.4.
  return pickle.loads(force_bytes(value))
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f230b7bed90>
Traceback (most recent call last):
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/utils/", line 228, in wrapper
    fn(*args, **kwargs)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/channels/management/commands/", line 54, in inner_run
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/core/management/", line 359, in check
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/core/management/", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/core/checks/", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/core/checks/", line 16, in check_url_config
    return check_resolver(resolver)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/core/checks/", line 26, in check_resolver
    return check_method()
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/urls/", line 254, in check
    for pattern in self.url_patterns:
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/utils/", line 35, in __get__
    res = instance.__dict__[] = self.func(instance)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/urls/", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/utils/", line 35, in __get__
    res = instance.__dict__[] = self.func(instance)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/urls/", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/home/aztrock/workspace/env/lib/python3.5/importlib/", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 673, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/aztrock/workspace/env/kibox/billing/", line 9, in <module>
    from app.usuarios import views as UserViews
  File "/home/aztrock/workspace/env/kibox/app/usuarios/", line 31, in <module>
    from .form import (
  File "/home/aztrock/workspace/env/kibox/app/usuarios/", line 102, in <module>
    class ProfileUserForm(forms.ModelForm):
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/forms/", line 261, in __new__
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/forms/", line 177, in fields_for_model
    formfield = f.formfield(**kwargs)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/db/models/fields/", line 981, in formfield
    'queryset': self.remote_field.model._default_manager.using(db),
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/db/models/", line 85, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/db/models/", line 1034, in using
    clone = self._clone()
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/db/models/", line 1103, in _clone
    query = self.query.clone()
  File "/home/aztrock/workspace/env/local/lib/python3.5/site-packages/django/db/models/sql/", line 297, in clone
    obj.select_for_update_skip_locked = self.select_for_update_skip_locked
AttributeError: 'Query' object has no attribute 'select_for_update_skip_locked'

#28499 fixed makemigrations fails on model with geometry field when the geo database is not the default one nobody Kaveh

Create a django app with two databases defined like this:

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'whatever'
    'postgres': {
        'ENGINE': 'django.contrib.gis.db.backends.postgis',
        'NAME': 'whatever'

and here is the database router:

POSTGRES_APPS = ['app1']

class PostgresRouter(object):
    def db_for_read(self, model, **hints):
        if model._meta.app_label in POSTGRES_APPS:
            return 'postgres'
        return None

    def db_for_write(self, model, **hints):
        if model._meta.app_label in POSTGRES_APPS:
            return 'postgres'
        return None

    def allow_relation(self, obj1, obj2, **hints):
        if {obj1._meta.app_label, obj2._meta.app_label}.issubset(set(POSTGRES_APPS)):
            return True
        return None

    def allow_migrate(self, db, app_label, model_name=None, **hints):
        if db == 'postgres':
            return app_label in POSTGRES_APPS
            return app_label not in POSTGRES_APPS

Create an app called app1 and add it to INSTALLED_APPS:

class Shapes(models.Model):
    shape = models.GeometryField()

Now if you run makemigrations, it throws the following error: AttributeError: 'DatabaseOperations' object has no attribute 'geo_db_type'

Seems like the error is because Django is using the default connection, i.e. mysql, for handling the geomtry field in app1, though this app is supposed to be part of the gis enabled database, i.e. postgres.

#28498 fixed Add cx_Oracle 6 support felixxm felixxm

cx_Oracle 6 causes a tests failures due to this change:

Prevent closing the connection when there are any open statements or LOBs and add new error “DPI-1054: connection cannot be closed when open statements or LOBs exist” when this situation is detected; this is needed to prevent crashes under certain conditions when statements or LOBs are being acted upon while at the same time (in another thread) a connection is being closed; it also prevents leaks of statements and LOBs when a connection is returned to a session pool. (see cx_Oracle release notes).

Sample exception:

Traceback (most recent call last):
  File "./", line 478, in <module>
  File "./", line 286, in django_tests
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/test/", line 601, in run_tests
    old_config = self.setup_databases()
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/test/", line 548, in setup_databases
    self.parallel, **kwargs
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/test/", line 176, in setup_databases
    serialize=connection.settings_dict.get('TEST', {}).get('SERIALIZE', True),
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/db/backends/base/", line 54, in create_test_db
    self._create_test_db(verbosity, autoclobber, keepdb)
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/db/backends/oracle/", line 100, in _create_test_db
    self._maindb_connection.close()  # done with main user -- test user and tablespaces created
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/db/backends/base/", line 281, in close
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/db/backends/base/", line 243, in _close
    return self.connection.close()
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/db/", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/jenkins/workspace/django-oracle-master/database/oracle12/label/trusty/python/python3.6/django/db/backends/base/", line 243, in _close
    return self.connection.close()
django.db.utils.DatabaseError: DPI-1054: connection cannot be closed when open statements or LOBs exist}}}
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