-
Notifications
You must be signed in to change notification settings - Fork 4.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add options for Query Based Parameter for a query with parameters #4648
base: master
Are you sure you want to change the base?
Conversation
(From @arikfr 's comment #3014 (comment))
After my first iterations with the backend I wouldn't say the static value has its complexity for validation rules. Since they are configured in the Parameter Edit, the values should be reliable (it's just a matter of computing them backend-wise on the validation). However, a bigger problem in the same manner is the Search parameter. At a moment I tried to handle the safety of Parameters with the real time Search enabled, but realized it falls back on being a Text Parameter (just with one more layer before it 😅). I'm not sure if you already had that in mind before, but I guess those will have to be a new entry on the "Unsafe param list". Based on this, I got a few options on how to proceed:
Personally I prefer going with 2 as that logic only made sense to me for the Search feature. Anyway, I'm sharing this in case you had other thoughts on this and to make sure I'll go into the right direction :) |
54ee363
to
9cf3965
Compare
It's an overlook on my part :-( Unfortunately you're right: for the original use case of a search parameter which is text based, we will have to mark those as unsafe. While option 1 is better, option 2 is also acceptable for first iteration as a text based parameter is the most common case anyway. |
495cb87
to
bb0d783
Compare
32fd151
to
e555642
Compare
|
||
if query.parameters: | ||
return False | ||
except (models.NoResultFound): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be used in other get_by_id_and_org
uses too?
- Change searchTerm separator - Add cy.wait
redash/models/parameterized_query.py
Outdated
try: | ||
query = models.Query.get_by_id_and_org(query_id, org) | ||
return bool(query.parameters) | ||
except (models.NoResultFound): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't we prefer that this blows up with a 404 in such a case? Returning False
implies that this query doesn't have parameters, but in-fact, it's a misconfigured parent query. It might make debugging harder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Returning False
was just the easy option (because it will invalidate any option you provide to the parameter), I actually just wanted to avoid the error happening on the server and check what should be done in the rest of this file (currently a server error happens for misconfigured parent queries due to _load_results too).
Rethinking about it, to better cover the misconfigured parameters at this point we can either create a new exception type or reuse InvalidParameterError
and blow up with a 400. IMO there's probably a more robust way, but showing "Your query has misconfigured parameterers: {}" error on query execution should be helpful enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated it to consider that NoResultFound
as an invalid parameter, the UI will still show it as required when editing. This should be enough help for identifying a problem with a query based dropdown.
@@ -166,7 +166,8 @@ def test_validates_enum_list_value_parameters(self): | |||
"redash.models.parameterized_query.dropdown_values", | |||
return_value=[{"value": "1"}], | |||
) | |||
def test_validation_accepts_integer_values_for_dropdowns(self, _): | |||
@patch("redash.models.parameterized_query.query_has_parameters", return_value=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not too happy about stubbing out implementation details such as query_has_parameters
. Is there a way to setup the data to organically provide this behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately my experience with the backend unit tests is very limited 😅, for this one I just cloned the behavior it had for load_results
since it was returning a "There is no app context".
Another option I have in mind is getting rid of that method and creating a get_query_by_id_and_org
(so the stub would be a query, not a boolean)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few months later and I'm a little bit better at this now 🙂. So, turns out the test_parameterized_query
is based in TestCase
, thus it doesn't have an App Context, we then can:
- Make it based in
BaseTestCase
, so that it will have an App Context for us to create an actual query. Downside: will make it slow; - Keep it like that, add a
_load_dropdown_query
that we can mock and keep mockingdropdown_values
with a fast running test;
Any preference in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test was actually harder to set with the organic App Context than I thought, so I'm back with the mocks, but I've updated the query_has_parameters
to be a mock on the Query object.
I realized that although way it works with making options coupled to a search term is better in terms of validating the options, this will cause UX issues 😕. So I'll take a stab at storing both Value and Label (both as the query default value and in the search url). |
Looking forward to this. |
@gabrieldutra This PR sounds useful. Should we leave this open? If you don't have time to look at it though, we can just close it. 😄 |
I see this as an important feature ) |
@konnectr Cool. 😄 Any interest in trying to finish the PR? |
What type of PR is this? (check all applicable)
Description
This PRs allows selecting a Parameterized Query for Query Based Parameters by mapping its parameters as Dropdown Search or Static value.
Related Tickets & Documents
#3014
Mobile & Desktop Screenshots/Recordings (if there are UI changes)