#11479 closed defect (fixed)
TicketQuery with progress format should support grouping by custom fields
| Reported by: | Owned by: | Peter Suter | |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0.2 |
| Component: | query system | Version: | 1.0.1 |
| Severity: | normal | Keywords: | custom field progress |
| Cc: | fbrettschneider@… | Branch: | |
| Release Notes: |
Fixed error in |
||
| API Changes: | |||
| Internal Changes: | |||
Description
I'm using SimpleMultiProjectPlugin, which creates a new custom field called "project". I would like to use TicketQuery to display tickets grouped by that field, but that doesn't seem to be supported. This generates an error:
[[TicketQuery(group=project,format=progress)]]
Attachments (1)
Change History (10)
comment:1 by , 12 years ago
| Cc: | added |
|---|
follow-up: 5 comment:2 by , 12 years ago
comment:3 by , 12 years ago
| Component: | general → query system |
|---|---|
| Keywords: | custom field progress added |
| Milestone: | → next-stable-1.0.x |
| Summary: | TicketQuery should support grouping by custom fields → TicketQuery with progress format should support grouping by custom fields |
| Type: | enhancement → defect |
Reproduced. TicketQuery(format=progress) macro with grouping custom field leads the issue.
2014-02-08 10:28:22,513 Trac[util] DEBUG: SQL:
SELECT DISTINCT COALESCE(project, '') FROM ticket
ORDER BY COALESCE(project, '')
2014-02-08 10:28:22,515 Trac[util] DEBUG: execute exception: OperationalError('no such column: project',)
2014-02-08 10:28:22,517 Trac[formatter] ERROR: Macro TicketQuery(group=project,format=progress) failed:
Traceback (most recent call last):
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/wiki/formatter.py", line 765, in _macro_formatter
return macro.ensure_inline(macro.process(args))
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/wiki/formatter.py", line 356, in process
text = self.processor(text)
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/wiki/formatter.py", line 343, in _macro_processor
text)
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/ticket/query.py", line 1375, in expand_macro
per_group_stats_data)
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/ticket/roadmap.py", line 356, in grouped_stats_data
""" % (by, by))]
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/db/api.py", line 122, in execute
return db.execute(query, params)
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/db/util.py", line 121, in execute
cursor.execute(query, params)
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/db/util.py", line 56, in execute
r = self.cursor.execute(sql)
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/db/sqlite_backend.py", line 78, in execute
result = PyFormatCursor.execute(self, *args)
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/db/sqlite_backend.py", line 56, in execute
args or [])
File "/home/jun66j5/venv/trac/1.0.1/lib/python2.5/site-packages/trac/db/sqlite_backend.py", line 48, in _rollback_on_error
return function(self, *args, **kwargs)
OperationalError: no such column: project
comment:4 by , 12 years ago
| Milestone: | next-stable-1.0.x → 1.0.2 |
|---|
comment:5 by , 12 years ago
I'm not sure how to detect if a
(none)group is needed.
I'm not that familiar with TracTicketsCustomFields. But Tickets created before a custom field has been defined will not have a value for that field. So it might be best to always add a (none) group. If it's not needed it will be skipped anyway.
comment:6 by , 12 years ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
by , 12 years ago
| Attachment: | T11479-query-progress-group-custom.patch added |
|---|
comment:7 by , 12 years ago
attachment:T11479-query-progress-group-custom.patch adds this and some testcases.
(Needs the patch from #10838 for shared test infrastructure.)
comment:8 by , 12 years ago
- We should use
COALESCE()forticket_custom.value. - We could use DB API rather than
query % argsfor custom fields. - Using
COALESCE('%s', '')is no sense….
-
trac/ticket/roadmap.py
diff --git a/trac/ticket/roadmap.py b/trac/ticket/roadmap.py index 8fa295f..9c4b425 100644
a b def grouped_stats_data(env, stats_provider, tickets, by, per_group_stats_data): 350 350 group_names = field['options'] 351 351 if field.get('optional'): 352 352 group_names.insert(0, '') 353 elif field.get('custom'):353 elif field.get('custom'): 354 354 group_names = [name for name, in env.db_query(""" 355 SELECT DISTINCT c.value FROM ticket_custom c 356 WHERE c.name=COALESCE('%s', '') 357 ORDER BY c.value 358 """ % (by, ))] 355 SELECT DISTINCT COALESCE(c.value, '') FROM ticket_custom c 356 WHERE c.name=%s ORDER BY COALESCE(c.value, '') 357 """, (by, ))] 359 358 if '' not in group_names: 360 359 group_names.insert(0, '') 361 360 else:
comment:9 by , 12 years ago
| Release Notes: | modified (diff) |
|---|---|
| Resolution: | → fixed |
| Status: | assigned → closed |



trac/ticket/roadmap.py
I'm not sure how to detect if a
(none)group is needed.