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
…30699)

(cherry picked from commit c9ff09a)
  • Loading branch information
michael-s-molina authored and sadpandajoe committed Oct 28, 2024
1 parent 7c569ab commit 49aa74c
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 @@ -1045,9 +1045,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 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,
force=True,
Expand Down Expand Up @@ -1515,15 +1517,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 49aa74c

Please sign in to comment.