You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2024/02/01 18:28:46 UTC

(superset) 01/01: fix(cache): remove unused webserver config & handle trailing slashes (#22849)

This is an automated email from the ASF dual-hosted git repository.

michaelsmolina pushed a commit to branch 3.0
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 05042facd33466059bb95c41e190e526e19d87d9
Author: Usiel Riedl <us...@automattic.com>
AuthorDate: Thu Feb 1 07:34:07 2024 -0800

    fix(cache): remove unused webserver config & handle trailing slashes (#22849)
---
 requirements/development.txt                       |  2 +-
 .../legacy-preset-chart-deckgl/src/index.js        |  1 -
 .../legacy-preset-chart-deckgl/src/layers/index.js |  2 -
 superset/config.py                                 |  4 --
 superset/tasks/cache.py                            |  4 +-
 tests/integration_tests/superset_test_config.py    |  1 -
 .../superset_test_config_thumbnails.py             |  1 -
 tests/integration_tests/tasks/test_cache.py        | 58 ++++++++++++++++++++++
 8 files changed, 61 insertions(+), 12 deletions(-)

diff --git a/requirements/development.txt b/requirements/development.txt
index 40cd7b6bc1..2083e8dd9e 100644
--- a/requirements/development.txt
+++ b/requirements/development.txt
@@ -94,7 +94,7 @@ pyasn1-modules==0.3.0
     # via python-ldap
 pydruid==0.6.5
     # via apache-superset
-pyhive[hive]==0.6.5
+pyhive[hive]==0.7.0
     # via apache-superset
 pyinstrument==4.4.0
     # via -r requirements/development.in
diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/index.js b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/index.js
index fc4aa7fca0..8618c3f78d 100644
--- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/index.js
+++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/index.js
@@ -26,5 +26,4 @@ export { default as PathChartPlugin } from './layers/Path';
 export { default as PolygonChartPlugin } from './layers/Polygon';
 export { default as ScatterChartPlugin } from './layers/Scatter';
 export { default as ScreengridChartPlugin } from './layers/Screengrid';
-export { default as ContourChartPlugin } from './layers/Contour';
 export { default as HeatmapChartPlugin } from './layers/Heatmap';
diff --git a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/index.js b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/index.js
index 9747a50b1e..8ca7e40e20 100644
--- a/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/index.js
+++ b/superset-frontend/plugins/legacy-preset-chart-deckgl/src/layers/index.js
@@ -26,7 +26,6 @@ import { getLayer as deck_geojson } from './Geojson/Geojson';
 import { getLayer as deck_arc } from './Arc/Arc';
 import { getLayer as deck_polygon } from './Polygon/Polygon';
 import { getLayer as deck_heatmap } from './Heatmap/Heatmap';
-import { getLayer as deck_contour } from './Contour/Contour';
 
 const layerGenerators = {
   deck_grid,
@@ -38,7 +37,6 @@ const layerGenerators = {
   deck_arc,
   deck_polygon,
   deck_heatmap,
-  deck_contour,
 };
 
 export default layerGenerators;
diff --git a/superset/config.py b/superset/config.py
index 6454ba6b7d..21e61586ec 100644
--- a/superset/config.py
+++ b/superset/config.py
@@ -156,10 +156,6 @@ FILTER_SELECT_ROW_LIMIT = 10000
 # values may be "Last day", "Last week", "<ISO date> : now", etc.
 DEFAULT_TIME_FILTER = NO_TIME_RANGE
 
-SUPERSET_WEBSERVER_PROTOCOL = "http"
-SUPERSET_WEBSERVER_ADDRESS = "0.0.0.0"
-SUPERSET_WEBSERVER_PORT = 8088
-
 # This is an important setting, and should be lower than your
 # [load balancer / proxy / envoy / kong / ...] timeout settings.
 # You should also make sure to configure your WSGI server
diff --git a/superset/tasks/cache.py b/superset/tasks/cache.py
index 01f6351919..1f60a5cd84 100644
--- a/superset/tasks/cache.py
+++ b/superset/tasks/cache.py
@@ -32,6 +32,7 @@ from superset.models.slice import Slice
 from superset.tags.models import Tag, TaggedObject
 from superset.utils.date_parser import parse_human_datetime
 from superset.utils.machine_auth import MachineAuthProvider
+from superset.utils.urls import get_url_path
 
 logger = get_task_logger(__name__)
 logger.setLevel(logging.INFO)
@@ -233,8 +234,7 @@ def fetch_url(data: str, headers: dict[str, str]) -> dict[str, str]:
     """
     result = {}
     try:
-        baseurl = "{WEBDRIVER_BASEURL}".format(**app.config)
-        url = f"{baseurl}api/v1/chart/warm_up_cache"
+        url = get_url_path("Superset.warm_up_cache")
         logger.info("Fetching %s with payload %s", url, data)
         req = request.Request(
             url, data=bytes(data, "utf-8"), headers=headers, method="PUT"
diff --git a/tests/integration_tests/superset_test_config.py b/tests/integration_tests/superset_test_config.py
index fd0da9f65f..42e4721ffe 100644
--- a/tests/integration_tests/superset_test_config.py
+++ b/tests/integration_tests/superset_test_config.py
@@ -36,7 +36,6 @@ SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(
     DATA_DIR, "unittests.integration_tests.db"
 )
 DEBUG = False
-SUPERSET_WEBSERVER_PORT = 8081
 SILENCE_FAB = False
 # Allowing SQLALCHEMY_DATABASE_URI and SQLALCHEMY_EXAMPLES_URI to be defined as an env vars for
 # continuous integration
diff --git a/tests/integration_tests/superset_test_config_thumbnails.py b/tests/integration_tests/superset_test_config_thumbnails.py
index 5bd02e7b0f..29efab53f4 100644
--- a/tests/integration_tests/superset_test_config_thumbnails.py
+++ b/tests/integration_tests/superset_test_config_thumbnails.py
@@ -24,7 +24,6 @@ SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(
     DATA_DIR, "unittests.integration_tests.db"
 )
 DEBUG = True
-SUPERSET_WEBSERVER_PORT = 8081
 
 # Allowing SQLALCHEMY_DATABASE_URI to be defined as an env var for
 # continuous integration
diff --git a/tests/integration_tests/tasks/test_cache.py b/tests/integration_tests/tasks/test_cache.py
new file mode 100644
index 0000000000..943b444f76
--- /dev/null
+++ b/tests/integration_tests/tasks/test_cache.py
@@ -0,0 +1,58 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from unittest import mock
+
+import pytest
+
+from tests.integration_tests.test_app import app
+
+
+@pytest.mark.parametrize(
+    "base_url",
+    [
+        "http://base-url",
+        "http://base-url/",
+    ],
+    ids=["Without trailing slash", "With trailing slash"],
+)
+@mock.patch("superset.tasks.cache.request.Request")
+@mock.patch("superset.tasks.cache.request.urlopen")
+def test_fetch_url(mock_urlopen, mock_request_cls, base_url):
+    from superset.tasks.cache import fetch_url
+
+    mock_request = mock.MagicMock()
+    mock_request_cls.return_value = mock_request
+
+    mock_urlopen.return_value = mock.MagicMock()
+    mock_urlopen.return_value.code = 200
+
+    app.config["WEBDRIVER_BASEURL"] = base_url
+    headers = {"key": "value"}
+    data = "data"
+    data_encoded = b"data"
+
+    result = fetch_url(data, headers)
+
+    assert data == result["success"]
+    mock_request_cls.assert_called_once_with(
+        "http://base-url/superset/warm_up_cache/",
+        data=data_encoded,
+        headers=headers,
+        method="PUT",
+    )
+    # assert the same Request object is used
+    mock_urlopen.assert_called_once_with(mock_request, timeout=mock.ANY)