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

lyndsi pushed a commit to branch 
lyndsi/sql-lab-new-explore-button-functionality-and-move-save-dataset-to-split-save-button
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 5110bb3b550977073fd06e35830e8b7a02f7bd6d
Author: AAfghahi <[email protected]>
AuthorDate: Fri Jun 24 13:53:31 2022 -0400

    added explore_json error
---
 superset/errors.py     |  7 +++++++
 superset/views/core.py | 11 +++++++++++
 2 files changed, 18 insertions(+)

diff --git a/superset/errors.py b/superset/errors.py
index 9198a82d3f..44ad2477cd 100644
--- a/superset/errors.py
+++ b/superset/errors.py
@@ -90,6 +90,9 @@ class SupersetErrorType(str, Enum):
     INVALID_PAYLOAD_FORMAT_ERROR = "INVALID_PAYLOAD_FORMAT_ERROR"
     INVALID_PAYLOAD_SCHEMA_ERROR = "INVALID_PAYLOAD_SCHEMA_ERROR"
 
+    # Dataset/Datasource Errors
+    CHART_TYPE_REQUIRES_DATASET_ERROR = "CHART_TYPE_REQUIRES_DATASET_ERROR"
+
 
 ISSUE_CODES = {
     1000: _("The datasource is too large to query."),
@@ -140,6 +143,9 @@ ISSUE_CODES = {
     1035: _("Failed to start remote query on a worker."),
     1036: _("The database was deleted."),
     1037: _("Custom SQL fields cannot contain sub-queries."),
+    1038: _(
+        "This chart type is not supported when using an unsaved query as a 
chart source."
+    ),
 }
 
 
@@ -177,6 +183,7 @@ ERROR_TYPES_TO_ISSUE_CODES_MAPPING = {
     SupersetErrorType.ASYNC_WORKERS_ERROR: [1035],
     SupersetErrorType.DATABASE_NOT_FOUND_ERROR: [1011, 1036],
     SupersetErrorType.CONNECTION_DATABASE_TIMEOUT: [1001, 1009],
+    SupersetErrorType.CHART_TYPE_REQUIRES_DATASET_ERROR: [1038],
 }
 
 
diff --git a/superset/views/core.py b/superset/views/core.py
index ab8604b602..fce24a2f3e 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -635,6 +635,7 @@ class Superset(BaseSupersetView):  # pylint: 
disable=too-many-public-methods
                 status=403,
             )
 
+        print("I am in explore json")
         form_data = get_form_data()[0]
         try:
             datasource_id, datasource_type = get_datasource_info(
@@ -642,6 +643,16 @@ class Superset(BaseSupersetView):  # pylint: 
disable=too-many-public-methods
             )
             force = request.args.get("force") == "true"
 
+            if datasource_type == "query":
+                raise SupersetErrorException(
+                    SupersetError(
+                        message=__(
+                            "This chart type is not supported when using an 
unsaved query as a chart source. Create a dataset to visualize your data."
+                        ),
+                        error_type=SupersetErrorType.DML_NOT_ALLOWED_ERROR,
+                        level=ErrorLevel.ERROR,
+                    )
+                )
             # TODO: support CSV, SQL query and other non-JSON types
             if (
                 is_feature_enabled("GLOBAL_ASYNC_QUERIES")

Reply via email to