Skip to content

Commit

Permalink
fix: Nested transaction is inactive when embedding dashboard (apache#…
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Oct 24, 2024
1 parent ee3befb commit c9ff09a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
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 @@ def trigger_celery() -> WerkzeugResponse:
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 @@ def set_embedded(self, dashboard: Dashboard) -> Response:
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
return self.response_400(message=error.messages)

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

0 comments on commit c9ff09a

Please sign in to comment.