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: Nested transaction is inactive when embedding dashboard #30699

Merged
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
5 changes: 3 additions & 2 deletions superset/cachekeys/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ def invalidate(self) -> Response:
CacheKey.cache_key.in_(cache_keys)
)

with db.session.begin_nested():
db.session.execute(delete_stmt)
db.session.execute(delete_stmt)
db.session.commit() # pylint: disable=consider-using-transaction

stats_logger_manager.instance.gauge(
"invalidated_cache", len(cache_keys)
Expand All @@ -126,6 +126,7 @@ def invalidate(self) -> Response:
len(datasource_uids),
)
except SQLAlchemyError as ex: # pragma: no cover
db.session.rollback() # pylint: disable=consider-using-transaction
logger.error(ex, exc_info=True)
return self.response_500(str(ex))
return self.response(201)
19 changes: 11 additions & 8 deletions superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1125,9 +1125,11 @@
logger.info("Triggering screenshot ASYNC")
cache_dashboard_screenshot.delay(
username=get_current_user(),
guest_token=g.user.guest_token
if get_current_user() and isinstance(g.user, GuestUser)
else None,
guest_token=(
g.user.guest_token
if get_current_user() and isinstance(g.user, GuestUser)
else None
),
dashboard_id=dashboard.id,
dashboard_url=dashboard_url,
cache_key=cache_key,
Expand Down Expand Up @@ -1595,15 +1597,16 @@
try:
body = self.embedded_config_schema.load(request.json)

with db.session.begin_nested():
embedded = EmbeddedDashboardDAO.upsert(
dashboard,
body["allowed_domains"],
)
embedded = EmbeddedDashboardDAO.upsert(
dashboard,
body["allowed_domains"],
)
db.session.commit() # pylint: disable=consider-using-transaction

result = self.embedded_response_schema.dump(embedded)
return self.response(200, result=result)
except ValidationError as error:
db.session.rollback() # pylint: disable=consider-using-transaction

Check warning on line 1609 in superset/dashboards/api.py

View check run for this annotation

Codecov / codecov/patch

superset/dashboards/api.py#L1609

Added line #L1609 was not covered by tests
return self.response_400(message=error.messages)

@expose("/<id_or_slug>/embedded", methods=("DELETE",))
Expand Down
Loading