You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/09/14 17:34:29 UTC

[GitHub] [superset] john-bodley commented on a diff in pull request #21469: fix: Supports form_data param in old Explore endpoint

john-bodley commented on code in PR #21469:
URL: https://github.com/apache/superset/pull/21469#discussion_r971109696


##########
superset/views/core.py:
##########
@@ -736,6 +738,40 @@ def import_dashboards(self) -> FlaskResponse:
             "superset/import_dashboards.html", databases=databases
         )
 
+    def get_redirect_url(self) -> str:
+        """Assembles the redirect URL to the new endpoint. It also replaces
+        the form_data param with a form_data_key by saving the original content
+        to the cache layer.
+        """
+        redirect_url = request.url.replace("/superset/explore", "/explore")
+        form_data_key = None
+        request_form_data = request.args.get("form_data")
+        if request_form_data:
+            parsed_form_data = loads_request_json(request_form_data)
+            slice_id = parsed_form_data.get(
+                "slice_id", int(request.args.get("slice_id", 0))
+            )
+            datasource = parsed_form_data.get("datasource")
+            if datasource:
+                parts = datasource.split("__")

Review Comment:
   ```suggestion
                   datasource_id, datasource_type = datasource.split("__")
   ```



##########
superset/views/core.py:
##########
@@ -736,6 +738,40 @@ def import_dashboards(self) -> FlaskResponse:
             "superset/import_dashboards.html", databases=databases
         )
 
+    def get_redirect_url(self) -> str:
+        """Assembles the redirect URL to the new endpoint. It also replaces
+        the form_data param with a form_data_key by saving the original content
+        to the cache layer.
+        """
+        redirect_url = request.url.replace("/superset/explore", "/explore")
+        form_data_key = None
+        request_form_data = request.args.get("form_data")
+        if request_form_data:
+            parsed_form_data = loads_request_json(request_form_data)
+            slice_id = parsed_form_data.get(
+                "slice_id", int(request.args.get("slice_id", 0))
+            )
+            datasource = parsed_form_data.get("datasource")
+            if datasource:
+                parts = datasource.split("__")
+                datasource_id = parts[0]
+                datasource_type = parts[1]
+                parameters = CommandParameters(
+                    datasource_id=datasource_id,
+                    datasource_type=datasource_type,
+                    chart_id=slice_id,
+                    form_data=request_form_data,
+                )
+                form_data_key = CreateFormDataCommand(parameters).run()
+        if form_data_key:
+            url = parse.urlparse(redirect_url)
+            query = parse.parse_qs(url.query)
+            query.pop("form_data")
+            query["form_data_key"] = [form_data_key]

Review Comment:
   Why this this an array?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org