Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(bootstrap-data): always check flashes #22659

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions superset/embedded/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import json
from typing import Callable

from flask import abort, g, request
from flask import abort, request
from flask_appbuilder import expose
from flask_login import AnonymousUserMixin, LoginManager
from flask_wtf.csrf import same_origin
Expand Down Expand Up @@ -77,7 +77,7 @@ def embedded(
)

bootstrap_data = {
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to keep user as an argument here, last time I made a bug and assumed that common_bootstrap_payload was user agnostic as it did not take any params

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'll reintroduce it 👍

"embedded": {
"dashboard_id": embedded.dashboard_id,
},
Expand Down
21 changes: 13 additions & 8 deletions superset/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def json_response(obj: Any, status: int = 200) -> FlaskResponse:
def render_app_template(self) -> FlaskResponse:
payload = {
"user": bootstrap_user_data(g.user, include_perms=True),
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
}
return self.render_template(
"superset/spa.html",
Expand Down Expand Up @@ -387,13 +387,12 @@ def menu_data(user: User) -> Dict[str, Any]:


@cache_manager.cache.memoize(timeout=60)
def common_bootstrap_payload(user: User) -> Dict[str, Any]:
def cached_common_bootstrap_data(user: User) -> Dict[str, Any]:
"""Common data always sent to the client

The function is memoized as the return value only changes based
on configuration and feature flag values.
The function is memoized as the return value only changes when user permissions
or configuration values change.
"""
messages = get_flashed_messages(with_categories=True)
locale = str(get_locale())

# should not expose API TOKEN to frontend
Expand All @@ -417,7 +416,6 @@ def common_bootstrap_payload(user: User) -> Dict[str, Any]:
frontend_config["HAS_GSHEETS_INSTALLED"] = bool(available_specs[GSheetsEngineSpec])

bootstrap_data = {
"flash_messages": messages,
"conf": frontend_config,
"locale": locale,
"language_pack": get_language_pack(locale),
Expand All @@ -431,6 +429,13 @@ def common_bootstrap_payload(user: User) -> Dict[str, Any]:
return bootstrap_data


def common_bootstrap_payload() -> Dict[str, Any]:
return {
**(cached_common_bootstrap_data(g.user)),
"flash_messages": get_flashed_messages(with_categories=True),
}


def get_error_level_from_status_code( # pylint: disable=invalid-name
status: int,
) -> ErrorLevel:
Expand Down Expand Up @@ -536,7 +541,7 @@ def show_unexpected_exception(ex: Exception) -> FlaskResponse:
def get_common_bootstrap_data() -> Dict[str, Any]:
def serialize_bootstrap_data() -> str:
return json.dumps(
{"common": common_bootstrap_payload(g.user)},
{"common": common_bootstrap_payload()},
default=utils.pessimistic_json_iso_dttm_ser,
)

Expand All @@ -554,7 +559,7 @@ class SupersetModelView(ModelView):
def render_app_template(self) -> FlaskResponse:
payload = {
"user": bootstrap_user_data(g.user, include_perms=True),
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
}
return self.render_template(
"superset/spa.html",
Expand Down
10 changes: 5 additions & 5 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ def explore(
"force": force,
"user": bootstrap_user_data(g.user, include_perms=True),
"forced_height": request.args.get("height"),
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
}
if slc:
title = slc.slice_name
Expand Down Expand Up @@ -1960,7 +1960,7 @@ def dashboard(

bootstrap_data = {
"user": bootstrap_user_data(g.user, include_perms=True),
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
}

return self.render_template(
Expand Down Expand Up @@ -2691,7 +2691,7 @@ def welcome(self) -> FlaskResponse:

payload = {
"user": bootstrap_user_data(g.user, include_perms=True),
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
}

return self.render_template(
Expand Down Expand Up @@ -2720,7 +2720,7 @@ def profile(self, username: str) -> FlaskResponse:

payload = {
"user": bootstrap_user_data(user, include_perms=True),
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
}

return self.render_template(
Expand Down Expand Up @@ -2784,7 +2784,7 @@ def sqllab(self) -> FlaskResponse:
"""SQL Editor"""
payload = {
"defaultDbId": config["SQLLAB_DEFAULT_DBID"],
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
**self._get_sqllab_tabs(get_user_id()),
}

Expand Down
2 changes: 1 addition & 1 deletion superset/views/dashboard/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def embedded(
)

bootstrap_data = {
"common": common_bootstrap_payload(g.user),
"common": common_bootstrap_payload(),
"embedded": {"dashboard_id": dashboard_id_or_slug},
}

Expand Down