mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 01:25:16 +00:00
Propagate query execution errors from Celery tasks properly (#2713)
Refs https://github.com/mozilla/redash/issues/458
This commit is contained in:
parent
4d2df72f1f
commit
341a68c7d4
@ -466,6 +466,8 @@ class QueryExecutor(object):
|
||||
self.scheduled_query = models.db.session.merge(self.scheduled_query, load=False)
|
||||
self.scheduled_query.schedule_failures += 1
|
||||
models.db.session.add(self.scheduled_query)
|
||||
models.db.session.commit()
|
||||
raise result
|
||||
else:
|
||||
if (self.scheduled_query and self.scheduled_query.schedule_failures > 0):
|
||||
self.scheduled_query = models.db.session.merge(self.scheduled_query, load=False)
|
||||
@ -482,8 +484,8 @@ class QueryExecutor(object):
|
||||
self._log_progress('finished')
|
||||
|
||||
result = query_result.id
|
||||
models.db.session.commit()
|
||||
return result
|
||||
models.db.session.commit()
|
||||
return result
|
||||
|
||||
def _annotate_query(self, query_runner):
|
||||
if query_runner.annotate_query():
|
||||
|
@ -7,7 +7,8 @@ import mock
|
||||
from tests import BaseTestCase
|
||||
from redash import redis_connection, models
|
||||
from redash.query_runner.pg import PostgreSQL
|
||||
from redash.tasks.queries import QueryTaskTracker, enqueue_query, execute_query
|
||||
from redash.tasks.queries import (QueryExecutionError, QueryTaskTracker,
|
||||
enqueue_query, execute_query)
|
||||
|
||||
|
||||
class TestPrune(TestCase):
|
||||
@ -113,11 +114,15 @@ class QueryExecutorTests(BaseTestCase):
|
||||
{'routing_key': 'test'})
|
||||
q = self.factory.create_query(query_text="SELECT 1, 2", schedule=300)
|
||||
with cm, mock.patch.object(PostgreSQL, "run_query") as qr:
|
||||
qr.exception = ValueError("broken")
|
||||
execute_query("SELECT 1, 2", self.factory.data_source.id, {}, scheduled_query_id=q.id)
|
||||
qr.side_effect = ValueError("broken")
|
||||
with self.assertRaises(QueryExecutionError):
|
||||
execute_query("SELECT 1, 2", self.factory.data_source.id, {},
|
||||
scheduled_query_id=q.id)
|
||||
q = models.Query.get_by_id(q.id)
|
||||
self.assertEqual(q.schedule_failures, 1)
|
||||
execute_query("SELECT 1, 2", self.factory.data_source.id, {}, scheduled_query_id=q.id)
|
||||
with self.assertRaises(QueryExecutionError):
|
||||
execute_query("SELECT 1, 2", self.factory.data_source.id, {},
|
||||
scheduled_query_id=q.id)
|
||||
q = models.Query.get_by_id(q.id)
|
||||
self.assertEqual(q.schedule_failures, 2)
|
||||
|
||||
@ -129,10 +134,11 @@ class QueryExecutorTests(BaseTestCase):
|
||||
{'routing_key': 'test'})
|
||||
q = self.factory.create_query(query_text="SELECT 1, 2", schedule=300)
|
||||
with cm, mock.patch.object(PostgreSQL, "run_query") as qr:
|
||||
qr.exception = ValueError("broken")
|
||||
execute_query("SELECT 1, 2",
|
||||
self.factory.data_source.id, {},
|
||||
scheduled_query_id=q.id)
|
||||
qr.side_effect = ValueError("broken")
|
||||
with self.assertRaises(QueryExecutionError):
|
||||
execute_query("SELECT 1, 2",
|
||||
self.factory.data_source.id, {},
|
||||
scheduled_query_id=q.id)
|
||||
q = models.Query.get_by_id(q.id)
|
||||
self.assertEqual(q.schedule_failures, 1)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user