Some types of Properties are not handled properly when Exporting from the Execute Query wizard
Module
sql__export
Describe the bug
When executing an SQL Export with Propeties of types checkbox and selection there are some problems, from user point of view:
- Boolean (checkbox) Property cannot be set to False because it will fail the bad_props check where the value of te Property is required to evaluate to True (see below).
- Selection value is returned as the hash of the option, which is not intuitive as the hash is not user-defined and not visible during the Property setting. User only see the "label" of the option. The hash values can only be ontained through debugging, or by exporting the values of various Options - not convenient.
To Reproduce
Versions Affected: 16.0, 17.0, 18.0 (basically all versions to date since the inclusion of Properties field):
Steps to reproduce the behavior:
- Create a working SQL Export with Properties of those types, (e.g. Boolean Test with Checkbox type, and Selecttion Test with Selection type - create a few Options for the Selection) exporting the value of the Properties into the result. (e.g. SELECT %(Selection Test)s::TEXT AS "Selection", %(Boolean Test)s::TEXT AS "Boolean")
- Validate the SQL Export by clicking the "Validate SQL Expression" button, then execute it by clicking the "Execute Query" button that appears.
- To test the Boolean type Property case, uncheck the Boolean Test Property, then click the "Export" button in the wizard. It will prompt an error "Please enter a values for the following properties : Boolean Test"
- Close the error message by clicking the "OK" button, then check the Boolean Test Property
- To test the Selection type Property case, select an Option in the Selection Test Property, and, keeping any checkboxes checked, click the "Export" button. Save and open the resulting file. Observe the value of the Selection column, it is a unknown hash value instead of the selected Option's label.
Expected behavior
At step 3, the wizard should not prompt error as it may be intentional.
At step 5, the value of Selection should be something that the user can recognise, which, presently, only the Option's label is available.
Additional context
The issue with the Selection value also happened for Properties of type Tags. However instead of unknown hash, the value is set to the Tag Label's value in lower case. So, it is still manageable though may not be intuitive.
Here is the code that blocks non-True values:
|
bad_props = [x for x in properties if not x["value"]] |
|
if bad_props: |
|
raise UserError( |
|
_("Please enter a values for the following properties : %s") |
|
% (",".join([x["string"] for x in bad_props])) |
|
) |
|
|
Line 31 shold exclude evaluation if prop["type"] == "boolean".
Here is the code that returns the value of Properties:
|
for prop in properties: |
|
if prop["type"] == "many2many": |
|
m2m_ids = [] |
|
for m2m_id in prop["value"]: |
|
m2m_ids.append(m2m_id[0]) |
|
variable_dict[prop["string"]] = tuple(m2m_ids) |
|
else: |
|
variable_dict[prop["string"]] = prop["value"] |
There should be a special handler for prop["type"] == "selection", something in the line of:
elif prop["type"] == "selection":
_sel_dict = dict(prop["selection"])
variable_dict[prop["string"]] = _sel_dict.get(prop["value"], "")
similar treatment may be preferred if prop["type"] == "tags", getting the list of Tags from tags key of the prop variable. However it cannot use the same approach as selection as the value of the tags key is a list of tuple of 3 values, not 2 values such as Selection.
Some aspects of this issue has been discussed in #1085
Some types of Properties are not handled properly when Exporting from the Execute Query wizard
Module
sql__export
Describe the bug
When executing an SQL Export with Propeties of types checkbox and selection there are some problems, from user point of view:
To Reproduce
Versions Affected: 16.0, 17.0, 18.0 (basically all versions to date since the inclusion of Properties field):
Steps to reproduce the behavior:
Expected behavior
At step 3, the wizard should not prompt error as it may be intentional.
At step 5, the value of Selection should be something that the user can recognise, which, presently, only the Option's label is available.
Additional context
The issue with the Selection value also happened for Properties of type Tags. However instead of unknown hash, the value is set to the Tag Label's value in lower case. So, it is still manageable though may not be intuitive.
Here is the code that blocks non-True values:
reporting-engine/sql_export/wizard/wizard_file.py
Lines 31 to 37 in 52e03a5
Line 31 shold exclude evaluation if
prop["type"] == "boolean".Here is the code that returns the value of Properties:
reporting-engine/sql_export/wizard/wizard_file.py
Lines 44 to 51 in 52e03a5
There should be a special handler for
prop["type"] == "selection", something in the line of:similar treatment may be preferred if prop["type"] == "tags", getting the list of Tags from tags key of the prop variable. However it cannot use the same approach as selection as the value of the tags key is a list of tuple of 3 values, not 2 values such as Selection.
Some aspects of this issue has been discussed in #1085