Skip to content
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

fix(reports): handle exceptions properly in scope #12811

Merged
merged 4 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions superset/tasks/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from typing import Iterator

import croniter
from dateutil import parser

from superset import app
from superset.commands.exceptions import CommandException
Expand Down Expand Up @@ -60,9 +61,10 @@ def scheduler() -> None:


@celery_app.task(name="reports.execute")
def execute(report_schedule_id: int, scheduled_dttm: datetime) -> None:
def execute(report_schedule_id: int, scheduled_dttm: str) -> None:
try:
AsyncExecuteReportScheduleCommand(report_schedule_id, scheduled_dttm).run()
scheduled_dttm_ = parser.parse(scheduled_dttm)
AsyncExecuteReportScheduleCommand(report_schedule_id, scheduled_dttm_).run()
except ReportScheduleUnexpectedError as ex:
logger.error("An unexpected occurred while executing the report: %s", ex)
except CommandException as ex:
Expand Down
7 changes: 4 additions & 3 deletions superset/utils/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
import logging
from typing import Iterator

import sqlalchemy as sa
from contextlib2 import contextmanager
from sqlalchemy import create_engine
from sqlalchemy.exc import SQLAlchemyError
from sqlalchemy.orm import Session, sessionmaker
from sqlalchemy.pool import NullPool

Expand All @@ -38,7 +39,7 @@ def session_scope(nullpool: bool) -> Iterator[Session]:
in a future version of Superset."
)
if nullpool:
engine = sa.create_engine(database_uri, poolclass=NullPool)
engine = create_engine(database_uri, poolclass=NullPool)
session_class = sessionmaker()
session_class.configure(bind=engine)
session = session_class()
Expand All @@ -49,7 +50,7 @@ def session_scope(nullpool: bool) -> Iterator[Session]:
try:
yield session
session.commit()
except Exception as ex:
except SQLAlchemyError as ex:
session.rollback()
logger.exception(ex)
raise
Expand Down