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

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


The following commit(s) were added to refs/heads/master by this push:
     new 4f97b739b1 fix: Broken Python tests on master after merging prefix 
branch (#33095)
4f97b739b1 is described below

commit 4f97b739b180a4185f35093ea04d4a8eb139dec0
Author: Martyn Gigg <[email protected]>
AuthorDate: Fri Apr 11 16:52:35 2025 +0100

    fix: Broken Python tests on master after merging prefix branch (#33095)
---
 superset/app.py                       | 12 +++++++++++-
 superset/utils/urls.py                | 11 +++++++++--
 superset/views/dashboard/views.py     |  2 +-
 tests/integration_tests/core_tests.py |  2 +-
 4 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/superset/app.py b/superset/app.py
index 3a1196c975..22d3a6ba7d 100644
--- a/superset/app.py
+++ b/superset/app.py
@@ -14,11 +14,21 @@
 # KIND, either express or implied.  See the License for the
 # specific language governing permissions and limitations
 # under the License.
+from __future__ import annotations
 
 import logging
 import os
+import sys
 from typing import cast, Iterable, Optional
-from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment
+
+if sys.version_info >= (3, 11):
+    from wsgiref.types import StartResponse, WSGIApplication, WSGIEnvironment
+else:
+    from typing import TYPE_CHECKING
+
+    if TYPE_CHECKING:
+        from _typeshed.wsgi import StartResponse, WSGIApplication, 
WSGIEnvironment
+
 
 from flask import Flask
 from werkzeug.exceptions import NotFound
diff --git a/superset/utils/urls.py b/superset/utils/urls.py
index 599ef95b3a..08b30dff68 100644
--- a/superset/utils/urls.py
+++ b/superset/utils/urls.py
@@ -15,10 +15,11 @@
 # specific language governing permissions and limitations
 # under the License.
 import urllib
+from contextlib import nullcontext
 from typing import Any
 from urllib.parse import urlparse
 
-from flask import current_app, url_for
+from flask import current_app, has_request_context, url_for
 
 
 def get_url_host(user_friendly: bool = False) -> str:
@@ -32,7 +33,13 @@ def headless_url(path: str, user_friendly: bool = False) -> 
str:
 
 
 def get_url_path(view: str, user_friendly: bool = False, **kwargs: Any) -> str:
-    return headless_url(url_for(view, **kwargs), user_friendly=user_friendly)
+    if has_request_context():
+        request_context = nullcontext
+    else:
+        request_context = current_app.test_request_context
+
+    with request_context():
+        return headless_url(url_for(view, **kwargs), 
user_friendly=user_friendly)
 
 
 def modify_url_query(url: str, **kwargs: Any) -> str:
diff --git a/superset/views/dashboard/views.py 
b/superset/views/dashboard/views.py
index cd30da021f..d5dd27718d 100644
--- a/superset/views/dashboard/views.py
+++ b/superset/views/dashboard/views.py
@@ -87,7 +87,7 @@ class Dashboard(BaseSupersetView):
         db.session.commit()  # pylint: disable=consider-using-transaction
         return redirect(
             url_for(
-                "Superset.dashboard", dashboard_id_or_slug=new_dashboard.id, 
edit=True
+                "Superset.dashboard", dashboard_id_or_slug=new_dashboard.id, 
edit="true"
             )
         )
 
diff --git a/tests/integration_tests/core_tests.py 
b/tests/integration_tests/core_tests.py
index 8fe424b1bd..84fb7f20df 100644
--- a/tests/integration_tests/core_tests.py
+++ b/tests/integration_tests/core_tests.py
@@ -866,7 +866,7 @@ class TestCore(SupersetTestCase):
         self.login(ADMIN_USERNAME)
         resp = self.client.get("superset/dashboard/p/123/")
 
-        expected_url = "/superset/dashboard/1?permalink_key=123&standalone=3"
+        expected_url = "/superset/dashboard/1/?permalink_key=123&standalone=3"
 
         assert resp.headers["Location"] == expected_url
         assert resp.status_code == 302

Reply via email to