TicketQuery Wiki Macro

The TicketQuery macro lets you display ticket information anywhere that accepts WikiFormatting. The query language used by the [[TicketQuery]] macro is described in the TracQuery page.

Usage

[[TicketQuery]]

Wiki macro listing tickets that match certain criteria.

This macro accepts a comma-separated list of keyed parameters, in the form "key=value".

If the key is the name of a field, the value must use the syntax of a filter specifier as defined in TracQuery#QueryLanguage. Note that this is not the same as the simplified URL syntax used for query: links starting with a ? character. Commas (,) can be included in field values by escaping them with a backslash (\).

Groups of field constraints to be OR-ed together can be separated by a literal or argument.

In addition to filters, several other named parameters can be used to control how the results are presented. All of them are optional.

The format parameter determines how the list of tickets is presented:

  • list -- the default presentation is to list the ticket ID next to the summary, with each ticket on a separate line.
  • compact -- the tickets are presented as a comma-separated list of ticket IDs.
  • count -- only the count of matching tickets is displayed
  • rawcount -- only the count of matching tickets is displayed, not even with a link to the corresponding query (since 1.1.1)
  • table -- a view similar to the custom query view (but without the controls)
  • progress -- a view similar to the milestone progress bars

The max parameter can be used to limit the number of tickets shown (defaults to 0, i.e. no maximum).

The order parameter sets the field used for ordering tickets (defaults to id).

The desc parameter indicates whether the order of the tickets should be reversed (defaults to false).

The group parameter sets the field used for grouping tickets (defaults to not being set).

The groupdesc parameter indicates whether the natural display order of the groups should be reversed (defaults to false).

The verbose parameter can be set to a true value in order to get the description for the listed tickets. For table format only. deprecated in favor of the rows parameter

The rows parameter can be used to specify which field(s) should be viewed as a row, e.g. rows=description|summary

The col parameter can be used to specify which fields should be viewed as columns. For table format only.

For compatibility with Trac 0.10, if there's a last positional parameter given to the macro, it will be used to specify the format. Also, using "&" as a field separator still works (except for order) but is deprecated.

Examples

Example Result Macro
Number of Triage tickets: 672 [[TicketQuery(status=new&milestone=,count)]]
Number of new tickets: 672 [[TicketQuery(status=new,count)]]
Number of reopened tickets: 0 [[TicketQuery(status=reopened,count)]]
Number of assigned tickets: 355 [[TicketQuery(status=assigned,count)]]
Number of invalid tickets: 5164 [[TicketQuery(status=closed,resolution=invalid,count)]]
Number of worksforme tickets: 1067 [[TicketQuery(status=closed,resolution=worksforme,count)]]
Number of duplicate tickets: 4318 [[TicketQuery(status=closed,resolution=duplicate,count)]]
Number of wontfix tickets: 4090 [[TicketQuery(status=closed,resolution=wontfix,count)]]
Number of fixed tickets: 18494 [[TicketQuery(status=closed,resolution=fixed,count)]]
Number of untriaged tickets (milestone unset): 1027 [[TicketQuery(status!=closed,milestone=,count)]]
Total number of tickets: 35134 [[TicketQuery(count)]]
Number of tickets reported or owned by current user: 1489 [[TicketQuery(reporter=$USER,or,owner=$USER,count)]]
Number of tickets created this month: 32 [[TicketQuery(created=thismonth..,count)]]
Number of closed Firefox tickets: 8 [[TicketQuery(status=closed,keywords~=firefox,count)]]
Number of closed Opera tickets: 24 [[TicketQuery(status=closed,keywords~=opera,count)]]
Number of closed tickets affecting Firefox and Opera: 0 [[TicketQuery(status=closed,keywords~=firefox opera,count)]]
Number of closed tickets affecting Firefox or Opera: 32 [[TicketQuery(status=closed,keywords~=firefox|opera,count)]]
Number of tickets that affect Firefox or are closed and affect Opera: 32 [[TicketQuery(status=closed,keywords~=opera,or,keywords~=firefox,count)]]
Number of closed Firefox tickets that don't affect Opera: 0 [[TicketQuery(status=closed,keywords~=firefox -opera,count)]]
Last 3 modified tickets: #28215, #35749, #21961 [[TicketQuery(max=3,order=modified,desc=1,compact)]]

Details of ticket #1:

[[TicketQuery(id=1,col=id|owner|reporter,rows=summary,table)]]

Ticket Owner Reporter
#1 Jacob Adrian Holovaty
Summary Create architecture for anonymous sessions

Format: list

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

This is displayed as:

No results

[[TicketQuery(id=123)]]

This is displayed as:

#123
Typo in the model_api/#field-types

Format: compact

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

This is displayed as:

No results

Format: count

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

This is displayed as:

0

Format: progress

[[TicketQuery(milestone=0.12.8&group=type,format=progress)]]

This is displayed as:

Uncategorized

1981 / 1982

Bug

10060 / 10400

New feature

3655 / 4048

Cleanup/optimization

5191 / 5483

Format: table

You can choose the columns displayed in the table format (format=table) using col=<field>. You can specify multiple fields and the 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:

Full rows

In table format you can specify full rows 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 34107)

1 2 3 4 5 6 7 8 9 10 11
Ticket Resolution Summary Owner Reporter
#35910 duplicate Use violation_error_message on UniqueContraint when only fields and no constraint is provided James Walters
Description

I have a model with the following UniqueConstraint:

models.UniqueConstraint(
  fields=["client", "location", "description", "affects_all_locations"],
  name="unique_desc_per_location_per_client",
  violation_error_message="A closure with this description already exists for this location (or all locations).",
)

Instead of seeing the error message I provided, I get "Closure with this Client, Location, Description and Affects all locations already exists." Upon consulting the documentation, I see that this is actually the intended behavior:

This message is not used for UniqueConstraints with fields and without a condition. Such UniqueConstraints show the same message as constraints defined with Field.unique or in Meta.unique_together.

The default error message, however, gives the names of model fields that users know nothing about, and the message I'm trying to provide gives the user a better explanation about what's going on. Currently, I would have to override the form's own validation to show this error message. However, I don't think this should be necessary, given that I can provide a violation_error_message straight to the UniqueConstraint.

I'm filing this under models/ORM since this is specifically related to model validation, though reclassify it as Forms if that turns out to be more appropriate.

If we decide we want to go in this direction, I'm open to working on a patch, but I'll wait to see if we agree that this behavior should be changed.

#35909 invalid Mutation of FormMixin.initial can cause a FormView with a formset to crash David Sanders
Description

Hi Djangonauts, long time no see… have been super busy, hope you're all well!

Here's an interesting problem with some backstory for which I never knew Django behaved like this.

So some of the old timers may know that FormMixin.initial is a mutable class attribute, and there have been past bug reports concerning this, the main one from 13 years ago is #16138

The fix for this was to call .copy() during get_initial().

However, I just spent a couple of days tracking down and fixing a 500 which was caused by this 😅 The direct cause for this was a junior dev mutating initial directly, not realising that because it is a class attribute then it's a long-living mutation.

Example

Given this simple example model setup:

class Foo(Model):
    foo = IntegerField()

class Bar(Model):
    foo = IntegerField()

and these 2 views:

class FooCreateView(CreateView):
    model = Foo
    fields = ["foo"]

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.initial["foo"] = 2

class BarCreateView(CreateView):
    model = Bar
    fields = ["foo"]

If you first visit FooCreateView, then visit BarCreateView; then this will have the unintended side-effect of initialising BarCreateView with 2.

This alone doesn't cause a 500 but it is a source of potential bug that may go unnoticed!

Furthermore if you create a FormView with a model formset, this will cause it to 500!

BarFormSet = modelformset_factory(Bar, fields=["foo"])

class LotsOfBarCreateView(FormView):
    template_name = "bars.html"
    form_class = BarFormSet

The unintended initialisation is incompatible with the way initialisation works with formsets - formsets expect a list, not a dictionary - see the traceback below

Potential Solution?

If we simply move the initialisation of initial to an __init__() the problem goes away. Furthermore I ran the full test suite with this change and nothing seems to break.

Claude seems to the only active contributor that was part of the original ticket - Would you (or anyone else) know why the solution wasn't to initialise from __init__() to begin with? I did see mention of it in a duplicate ticket #16701. The original ticket appears to be from prior GitHub times so there's no PR discussion to review.

index ebd071cf00..bff9ac68ce 100644
--- a/django/views/generic/edit.py
+++ b/django/views/generic/edit.py
@@ -13,11 +13,15 @@ from django.views.generic.detail import (
 class FormMixin(ContextMixin):
     """Provide a way to show and handle a form in a request."""

-    initial = {}
+    initial = None
     form_class = None
     success_url = None
     prefix = None

+    def __init__(self, *args, **kwargs):
+        super().__init__(*args, **kwargs)
+        self.initial = {}
+
     def get_initial(self):
         """Return the initial data to use for forms on this view."""
         return self.initial.copy()

Traceback

Here's the traceback:

Traceback (most recent call last):
  File "/path/to/test-project/django/core/handlers/exception.py", line 55, in inner
    response = get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/core/handlers/base.py", line 220, in _get_response
    response = response.render()
               ^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/response.py", line 114, in render
    self.content = self.rendered_content
                   ^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/response.py", line 92, in rendered_content
    return template.render(context, self._request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/backends/django.py", line 107, in render
    return self.template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 171, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 1016, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 1016, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 977, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 1081, in render
    return render_value_in_context(output, context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 1058, in render_value_in_context
    value = str(value)
            ^^^^^^^^^^
  File "/path/to/test-project/django/forms/utils.py", line 55, in render
    return mark_safe(renderer.render(template, context))
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/forms/renderers.py", line 29, in render
    return template.render(context, request=request).strip()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/backends/django.py", line 107, in render
    return self.template.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 171, in render
    return self._render(context)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 163, in _render
    return self.nodelist.render(context)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 1016, in render
    return SafeString("".join([node.render_annotated(context) for node in self]))
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 1016, in <listcomp>
    return SafeString("".join([node.render_annotated(context) for node in self]))
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/base.py", line 977, in render_annotated
    return self.render(context)
           ^^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/template/defaulttags.py", line 199, in render
    len_values = len(values)
                 ^^^^^^^^^^^
  File "/path/to/test-project/django/forms/formsets.py", line 121, in __len__
    return len(self.forms)
               ^^^^^^^^^^
  File "/path/to/test-project/django/utils/functional.py", line 47, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
                                         ^^^^^^^^^^^^^^^^^^^
  File "/path/to/test-project/django/forms/formsets.py", line 205, in forms
    return [
           ^
  File "/path/to/test-project/django/forms/formsets.py", line 206, in <listcomp>
    self._construct_form(i, **self.get_form_kwargs(i))
  File "/path/to/test-project/django/forms/models.py", line 740, in _construct_form
    kwargs["initial"] = self.initial_extra[i - self.initial_form_count()]
                        ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
KeyError: 0
#35907 invalid python manage.py runserver exits with ‘Watching for file changes with StatReloader Performing system checks’ Marica Fumagalli
Description

Hello, I have a django app on Windows 10 (django 5.0 and python 3.10). I installed Anaconda to create the specific environment, I managed to install all required libraries and I copied the related db on my computer. When I run "python manage.py runserver" or "python manage.py runserver localhost:8080", it returns this message and quit without giving me error: Watching for file changes with StatReloader Performing system checks...

If I run "python manage.py check" it doesn't return any error. I tried also "python manage.py runserver --noreload" but it exited again. I tried to uninstall and reinstall Anaconda. I made the same installation on Linux and everything works fine. Can you help me?

1 2 3 4 5 6 7 8 9 10 11


See also: TracQuery, TracTickets, TracReports

Last modified 10 months ago Last modified on Jan 24, 2024, 9:58:09 AM
Note: See TracWiki for help on using the wiki.
Back to Top