Skip to content

Commit

Permalink
fix alert executor
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Dec 9, 2022
1 parent fdc2698 commit 77d32e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions superset/reports/commands/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from celery.exceptions import SoftTimeLimitExceeded
from flask_babel import lazy_gettext as _

from superset import app, jinja_context
from superset import app, jinja_context, security_manager
from superset.commands.base import BaseCommand
from superset.reports.commands.exceptions import (
AlertQueryError,
Expand Down Expand Up @@ -149,10 +149,11 @@ def _execute_query(self) -> pd.DataFrame:
rendered_sql, ALERT_SQL_LIMIT
)

user = get_executor(
_, username = get_executor(
executor_types=app.config["ALERT_REPORTS_EXECUTE_AS"],
model=self._report_schedule,
)
user = security_manager.find_user(username)
with override_user(user):
start = default_timer()
df = self._report_schedule.database.get_df(sql=limited_rendered_sql)
Expand Down
10 changes: 5 additions & 5 deletions tests/integration_tests/reports/alert_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@
@pytest.mark.parametrize(
"owner_names,creator_name,config,expected_result",
[
(["gamma"], None, [ExecutorType.SELENIUM], (ExecutorType.SELENIUM, "admin")),
(["gamma"], None, [ExecutorType.OWNER], (ExecutorType.OWNER, "gamma")),
(["gamma"], None, [ExecutorType.SELENIUM], "admin"),
(["gamma"], None, [ExecutorType.OWNER], "gamma"),
(
["alpha", "gamma"],
"gamma",
[ExecutorType.CREATOR_OWNER],
(ExecutorType.CREATOR_OWNER, "gamma"),
"gamma",
),
(
["alpha", "gamma"],
"alpha",
[ExecutorType.CREATOR_OWNER],
(ExecutorType.CREATOR_OWNER, "alpha"),
"alpha",
),
(
["alpha", "gamma"],
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_execute_query_as_report_executor(
)
with cm:
command.run()
assert override_user_mock.call_args[0][0] == expected_result
assert override_user_mock.call_args[0][0].username == expected_result

app.config["ALERT_REPORTS_EXECUTE_AS"] = original_config

Expand Down

0 comments on commit 77d32e5

Please sign in to comment.