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 2023/07/28 17:33:15 UTC

[superset] branch master updated: fix(datasets): give possibility to add dataset with slashes in name (#24796)

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

michaelsmolina 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 64ced60f62 fix(datasets): give possibility to add dataset with slashes in name (#24796)
64ced60f62 is described below

commit 64ced60f62d87c7a3978fcbe17b0064b320cddd3
Author: Stepan <66...@users.noreply.github.com>
AuthorDate: Fri Jul 28 20:33:08 2023 +0300

    fix(datasets): give possibility to add dataset with slashes in name (#24796)
---
 superset/databases/api.py                      |  8 ++++----
 superset/views/core.py                         |  4 +++-
 tests/integration_tests/databases/api_tests.py | 16 ++++++++++++++++
 3 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/superset/databases/api.py b/superset/databases/api.py
index 98932e28e2..caa46d3164 100644
--- a/superset/databases/api.py
+++ b/superset/databases/api.py
@@ -672,7 +672,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
         except DatabaseTablesUnexpectedError as ex:
             return self.response_422(ex.message)
 
-    @expose("/<int:pk>/table/<table_name>/<schema_name>/", methods=("GET",))
+    @expose("/<int:pk>/table/<path:table_name>/<schema_name>/", methods=("GET",))
     @protect()
     @check_datasource_access
     @safe
@@ -735,7 +735,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
         self.incr_stats("success", self.table_metadata.__name__)
         return self.response(200, **table_info)
 
-    @expose("/<int:pk>/table_extra/<table_name>/<schema_name>/", methods=("GET",))
+    @expose("/<int:pk>/table_extra/<path:table_name>/<schema_name>/", methods=("GET",))
     @protect()
     @check_datasource_access
     @safe
@@ -798,8 +798,8 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
         )
         return self.response(200, **payload)
 
-    @expose("/<int:pk>/select_star/<table_name>/", methods=("GET",))
-    @expose("/<int:pk>/select_star/<table_name>/<schema_name>/", methods=("GET",))
+    @expose("/<int:pk>/select_star/<path:table_name>/", methods=("GET",))
+    @expose("/<int:pk>/select_star/<path:table_name>/<schema_name>/", methods=("GET",))
     @protect()
     @check_datasource_access
     @safe
diff --git a/superset/views/core.py b/superset/views/core.py
index 3655da0ed4..79fb3fbd8b 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -935,7 +935,9 @@ class Superset(BaseSupersetView):  # pylint: disable=too-many-public-methods
     @has_access
     @event_logger.log_this
     @expose("/fetch_datasource_metadata")
-    @deprecated(new_target="api/v1/database/<int:pk>/table/<table_name>/<schema_name>/")
+    @deprecated(
+        new_target="api/v1/database/<int:pk>/table/<path:table_name>/<schema_name>/"
+    )
     def fetch_datasource_metadata(self) -> FlaskResponse:
         """
         Fetch the datasource metadata.
diff --git a/tests/integration_tests/databases/api_tests.py b/tests/integration_tests/databases/api_tests.py
index ebf94219c3..bd39d96574 100644
--- a/tests/integration_tests/databases/api_tests.py
+++ b/tests/integration_tests/databases/api_tests.py
@@ -686,6 +686,22 @@ class TestDatabaseApi(SupersetTestCase):
         # the DB should not be created
         assert model is None
 
+    def test_get_table_details_with_slash_in_table_name(self):
+        table_name = "table_with/slash"
+        database = get_example_database()
+        query = f'CREATE TABLE IF NOT EXISTS "{table_name}" (col VARCHAR(256))'
+        if database.backend == "mysql":
+            query = query.replace('"', "`")
+
+        with database.get_sqla_engine_with_context() as engine:
+            engine.execute(query)
+
+        self.login(username="admin")
+        uri = f"api/v1/database/{database.id}/table/{table_name}/null/"
+        rv = self.client.get(uri)
+
+        self.assertEqual(rv.status_code, 200)
+
     def test_create_database_invalid_configuration_method(self):
         """
         Database API: Test create with an invalid configuration method.