You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2022/12/20 02:45:16 UTC

[superset] branch rm-dataset-name-convention created (now 3c0e357bed)

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

hugh pushed a change to branch rm-dataset-name-convention
in repository https://gitbox.apache.org/repos/asf/superset.git


      at 3c0e357bed first round of changes

This branch includes the following new commits:

     new 3c0e357bed first round of changes

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 01/01: first round of changes

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch rm-dataset-name-convention
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 3c0e357bede51b5916291135ab34faf38976b200
Author: hughhhh <hu...@gmail.com>
AuthorDate: Mon Dec 19 21:42:23 2022 -0500

    first round of changes
---
 .../exploreUtils/getParsedExploreURLParams.ts      | 18 +++----
 superset/connectors/base/models.py                 |  2 +-
 superset/connectors/sqla/views.py                  |  2 +-
 superset/explore/api.py                            | 12 ++---
 superset/explore/commands/get.py                   | 56 +++++++++++-----------
 superset/explore/commands/parameters.py            |  4 +-
 superset/explore/exceptions.py                     |  6 +--
 tests/integration_tests/core_tests.py              |  2 +-
 tests/unit_tests/explore/api_test.py               |  2 +-
 9 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/superset-frontend/src/explore/exploreUtils/getParsedExploreURLParams.ts b/superset-frontend/src/explore/exploreUtils/getParsedExploreURLParams.ts
index 0340dded75..f5b1471831 100644
--- a/superset-frontend/src/explore/exploreUtils/getParsedExploreURLParams.ts
+++ b/superset-frontend/src/explore/exploreUtils/getParsedExploreURLParams.ts
@@ -29,10 +29,10 @@ const EXPLORE_URL_SEARCH_PARAMS = {
     parser: (formData: string) => {
       const formDataObject = JSON.parse(formData);
       if (formDataObject.datasource) {
-        const [dataset_id, dataset_type] =
+        const [datasource_id, datasource_type] =
           formDataObject.datasource.split('__');
-        formDataObject.dataset_id = dataset_id;
-        formDataObject.dataset_type = dataset_type;
+        formDataObject.datasource_id = datasource_id;
+        formDataObject.datasource_type = datasource_type;
         delete formDataObject.datasource;
       }
       return formDataObject;
@@ -41,17 +41,17 @@ const EXPLORE_URL_SEARCH_PARAMS = {
   slice_id: {
     name: 'slice_id',
   },
-  dataset_id: {
-    name: 'dataset_id',
+  datasource_id: {
+    name: 'datasource_id',
   },
-  dataset_type: {
-    name: 'dataset_type',
+  datasource_type: {
+    name: 'datasource_type',
   },
   datasource: {
     name: 'datasource',
     parser: (datasource: string) => {
-      const [dataset_id, dataset_type] = datasource.split('__');
-      return { dataset_id, dataset_type };
+      const [datasource_id, datasouce_type] = datasource.split('__');
+      return { datasource_id, datasouce_type };
     },
   },
   form_data_key: {
diff --git a/superset/connectors/base/models.py b/superset/connectors/base/models.py
index b127229328..a03f088c07 100644
--- a/superset/connectors/base/models.py
+++ b/superset/connectors/base/models.py
@@ -209,7 +209,7 @@ class BaseDatasource(
     def explore_url(self) -> str:
         if self.default_endpoint:
             return self.default_endpoint
-        return f"/explore/?dataset_type={self.type}&dataset_id={self.id}"
+        return f"/explore/?datasource_type={self.type}&datasource_id={self.id}"
 
     @property
     def column_formats(self) -> Dict[str, Optional[str]]:
diff --git a/superset/connectors/sqla/views.py b/superset/connectors/sqla/views.py
index 7133cdfab9..c502f527ac 100644
--- a/superset/connectors/sqla/views.py
+++ b/superset/connectors/sqla/views.py
@@ -536,7 +536,7 @@ class TableModelView(  # pylint: disable=too-many-ancestors
         resp = super().edit(pk)
         if isinstance(resp, str):
             return resp
-        return redirect("/explore/?dataset_type=table&dataset_id={}".format(pk))
+        return redirect("/explore/?datasource_type=table&datasource_id={}".format(pk))
 
     @expose("/list/")
     @has_access
diff --git a/superset/explore/api.py b/superset/explore/api.py
index 7cce592d36..9eea542178 100644
--- a/superset/explore/api.py
+++ b/superset/explore/api.py
@@ -82,11 +82,11 @@ class ExploreRestApi(BaseApi):
           - in: query
             schema:
               type: integer
-            name: dataset_id
+            name: datasource_id
           - in: query
             schema:
               type: string
-            name: dataset_type
+            name: datasource_type
           responses:
             200:
               description: Returns the initial context.
@@ -110,8 +110,8 @@ class ExploreRestApi(BaseApi):
                 actor=g.user,
                 permalink_key=request.args.get("permalink_key", type=str),
                 form_data_key=request.args.get("form_data_key", type=str),
-                dataset_id=request.args.get("dataset_id", type=int),
-                dataset_type=request.args.get("dataset_type", type=str),
+                datasource_id=request.args.get("datasource_id", type=int),
+                datasource_type=request.args.get("datasource_type", type=str),
                 slice_id=request.args.get("slice_id", type=int),
             )
             result = GetExploreCommand(params).run()
@@ -124,8 +124,8 @@ class ExploreRestApi(BaseApi):
             return self.response(
                 403,
                 message=ex.message,
-                dataset_id=ex.dataset_id,
-                dataset_type=ex.dataset_type,
+                datasource_id=ex.datasource_id,
+                datasource_type=ex.datasource_type,
             )
         except (ChartNotFoundError, ExplorePermalinkGetFailedError) as ex:
             return self.response(404, message=str(ex))
diff --git a/superset/explore/commands/get.py b/superset/explore/commands/get.py
index 5bd42e2dc4..fb690a9d75 100644
--- a/superset/explore/commands/get.py
+++ b/superset/explore/commands/get.py
@@ -55,8 +55,8 @@ class GetExploreCommand(BaseCommand, ABC):
     ) -> None:
         self._permalink_key = params.permalink_key
         self._form_data_key = params.form_data_key
-        self._dataset_id = params.dataset_id
-        self._dataset_type = params.dataset_type
+        self._datasource_id = params.datasource_id
+        self._datasource_type = params.datasource_type
         self._slice_id = params.slice_id
 
     # pylint: disable=too-many-locals,too-many-branches,too-many-statements
@@ -87,10 +87,10 @@ class GetExploreCommand(BaseCommand, ABC):
                     message = _(
                         "Form data not found in cache, reverting to chart metadata."
                     )
-            elif self._dataset_id:
+            elif self._datasource_id:
                 initial_form_data[
                     "datasource"
-                ] = f"{self._dataset_id}__{self._dataset_type}"
+                ] = f"{self._datasource_id}__{self._datasource_type}"
                 if self._form_data_key:
                     message = _(
                         "Form data not found in cache, reverting to dataset metadata."
@@ -102,41 +102,43 @@ class GetExploreCommand(BaseCommand, ABC):
             initial_form_data=initial_form_data,
         )
         try:
-            self._dataset_id, self._dataset_type = get_datasource_info(
-                self._dataset_id, self._dataset_type, form_data
+            self._datasource_id, self._datasource_type = get_datasource_info(
+                self._datasource_id, self._datasource_type, form_data
             )
         except SupersetException:
-            self._dataset_id = None
+            self._datasource_id = None
             # fallback unkonw datasource to table type
-            self._dataset_type = SqlaTable.type
+            self._datasource_type = SqlaTable.type
 
-        dataset: Optional[BaseDatasource] = None
-        if self._dataset_id is not None:
+        datasource: Optional[BaseDatasource] = None
+        if self._datasource_id is not None:
             try:
-                dataset = DatasourceDAO.get_datasource(
-                    db.session, cast(str, self._dataset_type), self._dataset_id
+                datasource = DatasourceDAO.get_datasource(
+                    db.session, cast(str, self._datasource_type), self._datasource_id
                 )
             except DatasourceNotFound:
                 pass
-        dataset_name = dataset.name if dataset else _("[Missing Dataset]")
+        datasource_name = datasource.name if datasource else _("[Missing Dataset]")
 
-        if dataset:
+        if datasource:
             if current_app.config["ENABLE_ACCESS_REQUEST"] and (
-                not security_manager.can_access_datasource(dataset)
+                not security_manager.can_access_datasource(datasource)
             ):
-                message = __(security_manager.get_datasource_access_error_msg(dataset))
+                message = __(
+                    security_manager.get_datasource_access_error_msg(datasource)
+                )
                 raise DatasetAccessDeniedError(
                     message=message,
-                    dataset_type=self._dataset_type,
-                    dataset_id=self._dataset_id,
+                    datasource_type=self._datasource_type,
+                    datasource_id=self._datasource_id,
                 )
 
         viz_type = form_data.get("viz_type")
-        if not viz_type and dataset and dataset.default_endpoint:
-            raise WrongEndpointError(redirect=dataset.default_endpoint)
+        if not viz_type and datasource and datasource.default_endpoint:
+            raise WrongEndpointError(redirect=datasource.default_endpoint)
 
         form_data["datasource"] = (
-            str(self._dataset_id) + "__" + cast(str, self._dataset_type)
+            str(self._datasource_id) + "__" + cast(str, self._datasource_type)
         )
 
         # On explore, merge legacy/extra filters and URL params into the form data
@@ -145,16 +147,16 @@ class GetExploreCommand(BaseCommand, ABC):
         utils.merge_request_params(form_data, request.args)
 
         # TODO: this is a dummy placeholder - should be refactored to being just `None`
-        dataset_data: Dict[str, Any] = {
-            "type": self._dataset_type,
-            "name": dataset_name,
+        datasource_data: Dict[str, Any] = {
+            "type": self._datasource_type,
+            "name": datasource_name,
             "columns": [],
             "metrics": [],
             "database": {"id": 0, "backend": ""},
         }
         try:
-            if dataset:
-                dataset_data = dataset.data
+            if datasource:
+                datasource_data = datasource.data
         except SupersetException as ex:
             message = ex.message
         except SQLAlchemyError:
@@ -178,7 +180,7 @@ class GetExploreCommand(BaseCommand, ABC):
                 metadata["changed_by"] = slc.changed_by.get_full_name()
 
         return {
-            "dataset": sanitize_datasource_data(dataset_data),
+            "dataset": sanitize_datasource_data(datasource_data),
             "form_data": form_data,
             "slice": slc.data if slc else None,
             "message": message,
diff --git a/superset/explore/commands/parameters.py b/superset/explore/commands/parameters.py
index 7d16fee081..96d72f2670 100644
--- a/superset/explore/commands/parameters.py
+++ b/superset/explore/commands/parameters.py
@@ -25,6 +25,6 @@ class CommandParameters:
     actor: User
     permalink_key: Optional[str]
     form_data_key: Optional[str]
-    dataset_id: Optional[int]
-    dataset_type: Optional[str]
+    datasource_id: Optional[int]
+    datasource_type: Optional[str]
     slice_id: Optional[int]
diff --git a/superset/explore/exceptions.py b/superset/explore/exceptions.py
index ff375de147..e3b589c667 100644
--- a/superset/explore/exceptions.py
+++ b/superset/explore/exceptions.py
@@ -27,11 +27,11 @@ from superset.commands.exceptions import (
 
 class DatasetAccessDeniedError(ForbiddenError):
     def __init__(
-        self, message: str, dataset_id: Optional[int], dataset_type: Optional[str]
+        self, message: str, datasource_id: Optional[int], datasource_type: Optional[str]
     ) -> None:
         self.message = message
-        self.dataset_id = dataset_id
-        self.dataset_type = dataset_type
+        self.datasource_id = datasource_id
+        self.datasource_type = datasource_type
         super().__init__(self.message)
 
 
diff --git a/tests/integration_tests/core_tests.py b/tests/integration_tests/core_tests.py
index 6de21a7200..6e9f1a8d33 100644
--- a/tests/integration_tests/core_tests.py
+++ b/tests/integration_tests/core_tests.py
@@ -1419,7 +1419,7 @@ class TestCore(SupersetTestCase):
             "/superset/welcome",
             f"/superset/dashboard/{dash_id}/",
             "/superset/profile/admin/",
-            f"/explore/?dataset_type=table&dataset_id={tbl_id}",
+            f"/explore/?datasource_type=table&datasource_id={tbl_id}",
         ]
         for url in urls:
             data = self.get_resp(url)
diff --git a/tests/unit_tests/explore/api_test.py b/tests/unit_tests/explore/api_test.py
index 7f6d8ee2b2..147790844d 100644
--- a/tests/unit_tests/explore/api_test.py
+++ b/tests/unit_tests/explore/api_test.py
@@ -24,7 +24,7 @@ def test_explore_datasource_not_found(client: Any, full_api_access: None) -> Non
     # validating the payload for a dataset that doesn't exist
     # user should be expecting missing_datasource view
     response = client.get(
-        "/api/v1/explore/?dataset_id=50000&dataset_type=table",
+        "/api/v1/explore/?datasource_id=50000&datasource_type=table",
     )
     response.json["result"]["dataset"]["name"] == "[Missing Dataset]"
     assert response.status_code == 200