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(explore): Persist URL params to form-data #21792

Merged
merged 1 commit into from
Oct 13, 2022
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
7 changes: 4 additions & 3 deletions superset/explore/commands/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Any, cast, Dict, Optional

import simplejson as json
from flask import current_app as app
Copy link
Member Author

Choose a reason for hiding this comment

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

No need for misdirection.

from flask import current_app, request
from flask_babel import gettext as __, lazy_gettext as _
from sqlalchemy.exc import SQLAlchemyError

Expand Down Expand Up @@ -121,7 +121,7 @@ def run(self) -> Optional[Dict[str, Any]]:
dataset_name = dataset.name if dataset else _("[Missing Dataset]")

if dataset:
if app.config["ENABLE_ACCESS_REQUEST"] and (
if current_app.config["ENABLE_ACCESS_REQUEST"] and (
not security_manager.can_access_datasource(dataset)
):
message = __(security_manager.get_datasource_access_error_msg(dataset))
Expand All @@ -139,9 +139,10 @@ def run(self) -> Optional[Dict[str, Any]]:
str(self._dataset_id) + "__" + cast(str, self._dataset_type)
)

# On explore, merge legacy and extra filters into the form data
# On explore, merge legacy/extra filters and URL params into the form data
utils.convert_legacy_filters_into_adhoc(form_data)
utils.merge_extra_filters(form_data)
utils.merge_request_params(form_data, request.args)

dummy_dataset_data: Dict[str, Any] = {
"type": self._dataset_type,
Expand Down
12 changes: 12 additions & 0 deletions tests/integration_tests/explore/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,15 @@ def test_wrong_endpoint(mock_get_datasource, test_client, login_as_admin, datase
data = json.loads(resp.data.decode("utf-8"))
assert resp.status_code == 302
assert data["redirect"] == dataset.default_endpoint


def test_get_url_params(test_client, login_as_admin, chart_id):
resp = test_client.get(f"api/v1/explore/?slice_id={chart_id}&foo=bar")
assert resp.status_code == 200
data = json.loads(resp.data.decode("utf-8"))
result = data.get("result")

assert result["form_data"]["url_params"] == {
"foo": "bar",
"slice_id": str(chart_id),
}