#11837 closed enhancement (fixed)
support "optional" parameters in TracReports
Reported by: | Christian Boos | Owned by: | Christian Boos |
---|---|---|---|
Priority: | normal | Milestone: | 1.3.1 |
Component: | report system | Version: | 1.1dev |
Severity: | normal | Keywords: | |
Cc: | leho@…, trac.edgewall.org@… | Branch: | |
Release Notes: |
Default values for TracReports dynamic variables can be specified in the SQL query itself, inside SQL comments. |
||
API Changes: | |||
Internal Changes: |
Description (last modified by )
Currently if a report uses a user-defined parameter and that parameter is not defined, a warning is displayed (see e.g. {14}).
In case of complex reports with many user-defined parameters, that's a bit unfortunate as it's very easy to cope with missing values in the SQL query, e.g.
... WHERE ($AUTHOR_ IS '' OR author LIKE $AUTHOR_) ...
Original proposal
I propose to consider parameter names ending with "_" to be considered as "optional":
- they don't trigger the warning if left empty
- their name is rendered specially in the Parameters box to show that they're optional (with the example above, it would be:
(AUTHOR)
)
I also made the "foldable" legend use a bigger font size.
Updated proposal
The idea about the trailing "_" was abandoned in favor of specifying the default value for the dynamic variables in the SQL query, inside a SQL comment. See comment:5.
Attachments (3)
Change History (23)
by , 10 years ago
Attachment: | TracReports-optional-parameters.png added |
---|
by , 10 years ago
Attachment: | 0001-TracReports-parameter-names-ending-with-_-become-opt.patch added |
---|
proposed changes on top of r13350
comment:1 by , 10 years ago
Cc: | added |
---|
comment:2 by , 10 years ago
Tested and works well. One place for a documentation update is TracReports#AdvancedReports:DynamicVariables.
comment:3 by , 10 years ago
Is there a way to specify the default value for parameters? That would be very useful.
follow-up: 5 comment:4 by , 10 years ago
Having the possibility to define a default value would indeed by useful. However I don't see where. In TracIni you'd need to be admin to do that and anyway having to edit the report in two different places is not optimal. In the report itself, there's no obvious place either:
- as a SQL comment?
-- REVIEWER_=$USER
. Easy enough, but looks a bit hackish. - as a Wiki parameter?
{{{#!param name="REVIEWER_" value="$USER"}}}
… Well, it's not implemented yet ;-)
comment:5 by , 10 years ago
Replying to cboos:
- as a SQL comment?
-- REVIEWER_=$USER
. Easy enough, but looks a bit hackish.
I'd be happy with that. Also, you could drop the underscore, right? All parameters with such defaults would be optional.
by , 10 years ago
Attachment: | T11837-Report-argument-defaults-in-comments.patch added |
---|
follow-up: 7 comment:6 by , 10 years ago
This patch implements the simple case -- REVIEWER=psuter
. (Supporting -- REVIEWER=$USER
sounded easy, but I got stuck preventing -- REVIEWER=%s
raising ProgrammingError: Incorrect number of bindings supplied
.)
follow-up: 8 comment:7 by , 10 years ago
Replying to psuter:
Supporting
-- REVIEWER=$USER
sounded easy, but I got stuck preventing-- REVIEWER=%s
raisingProgrammingError: Incorrect number of bindings supplied
.)
Removing the default parameter assignments from the SQL solves that part.
comment:8 by , 10 years ago
Sounds good. But defaults should not replace explicit arguments:
-
trac/ticket/report.py
diff -r ab60c8583e04 trac/ticket/report.py
a b 812 812 813 813 def get_default_var_args(self, report_args, sql): 814 814 def extract_default_var(fullmatch): 815 report_args [fullmatch.group(1)] = fullmatch.group(2)815 report_args.setdefault(fullmatch.group(1), fullmatch.group(2)) 816 816 return self.arg_default_re.sub(extract_default_var, sql) 817 817 818 818 def sql_sub_vars(self, sql, args):
Another option to implement the indirection would be:
defaultval = sub_vars(fullmatch.group(2), report_args) report_args.setdefault(fullmatch.group(1), defaultval)
comment:9 by , 10 years ago
Milestone: | 1.1.3 → 1.1.4 |
---|
comment:10 by , 10 years ago
Milestone: | 1.1.4 → 1.1.5 |
---|
comment:11 by , 10 years ago
Milestone: | 1.1.5 → 1.1.6 |
---|
Retargeting tickets that I think won't be completed for 1.1.5, but please move back if I'm incorrect.
comment:12 by , 9 years ago
Milestone: | 1.1.6 → next-dev-1.1.x |
---|
comment:13 by , 9 years ago
Milestone: | next-dev-1.1.x → 1.2 |
---|---|
Owner: | changed from | to
Status: | new → assigned |
comment:15 by , 9 years ago
Would you like to push the changes this week, or should we retarget it to milestone:1.3.1?
comment:16 by , 9 years ago
Milestone: | 1.2 → 1.3.1 |
---|
Very busy month for me as well, unfortunately. Yeah, this one shouldn't hold back the release.
comment:17 by , 8 years ago
comment:18 by , 8 years ago
Is it possible to backport this feature to the next 1.2.x release? The changeset only affects 3 files, so the risk of conflicts is small. I fear that we would have to wait long for this feature otherwise, as 1.2 already took 4 years to be released.
comment:19 by , 8 years ago
Cc: | added |
---|
comment:20 by , 6 years ago
Release Notes: | modified (diff) |
---|
example with two optional parameters and a mandatory one