refresh_queries requires Request Context (#4045)

* avoid using 'abort' in parameterized query - raise an exception instead

* when facing invalid parameters or detached dropdown queries - continue to refresh the rest of the outdated queries

* test that dropdown queries detached from data source raise an exception when fetch values is attempted

* test that queries with invalid parameters arent refreshed

* test that queries with dropdown query parameters which are detached from the data source are skipped

* fix stale test double name

* newlines. newlines everywhere.

* pass org into dropdown_values

* pass in org in every ParameterizedQuery usage

* Update redash/tasks/queries.py

Co-Authored-By: Arik Fraimovich <arik@arikfr.com>

* reduce refresh_queries log noise

* track failure count for queries that failed to apply parameters, and also notify the failures

* Update redash/tasks/queries.py

Co-Authored-By: Arik Fraimovich <arik@arikfr.com>

* newlines. newlines everywhere.
This commit is contained in:
Omer Lachish
2019-08-09 15:26:31 +03:00
committed by Arik Fraimovich
parent cf7aef1e16
commit 76fbe858ba
7 changed files with 105 additions and 33 deletions

View File

@@ -65,3 +65,42 @@ class TestRefreshQuery(BaseTestCase):
add_job_mock.assert_called_with(
"select 42", query.data_source, query.user_id,
scheduled_query=query, metadata=ANY)
def test_doesnt_enqueue_parameterized_queries_with_invalid_parameters(self):
"""
Scheduled queries with invalid parameters are skipped.
"""
query = self.factory.create_query(
query_text="select {{n}}",
options={"parameters": [{
"global": False,
"type": "text",
"name": "n",
"value": 42, # <-- should be text!
"title": "n"}]})
oq = staticmethod(lambda: [query])
with patch('redash.tasks.queries.enqueue_query') as add_job_mock, \
patch.object(Query, 'outdated_queries', oq):
refresh_queries()
add_job_mock.assert_not_called()
def test_doesnt_enqueue_parameterized_queries_with_dropdown_queries_that_are_detached_from_data_source(self):
"""
Scheduled queries with a dropdown parameter which points to a query that is detached from its data source are skipped.
"""
query = self.factory.create_query(
query_text="select {{n}}",
options={"parameters": [{
"global": False,
"type": "query",
"name": "n",
"queryId": 100,
"title": "n"}]})
dropdown_query = self.factory.create_query(id=100, data_source=None)
oq = staticmethod(lambda: [query])
with patch('redash.tasks.queries.enqueue_query') as add_job_mock, \
patch.object(Query, 'outdated_queries', oq):
refresh_queries()
add_job_mock.assert_not_called()