You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2026/09/01 16:45:36 UTC

(superset) branch fix-jsondecodeerror-gsheets-validate-parameters created (now be0a0f26f85)

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

eschutho pushed a change to branch fix-jsondecodeerror-gsheets-validate-parameters
in repository https://gitbox.apache.org/repos/asf/superset.git


      at be0a0f26f85 fix(gsheets): catch JSONDecodeError in validate_parameters for malformed service_account_info

This branch includes the following new commits:

     new be0a0f26f85 fix(gsheets): catch JSONDecodeError in validate_parameters for malformed service_account_info

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: fix(gsheets): catch JSONDecodeError in validate_parameters for malformed service_account_info

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

eschutho pushed a commit to branch fix-jsondecodeerror-gsheets-validate-parameters
in repository https://gitbox.apache.org/repos/asf/superset.git

commit be0a0f26f856dbfcb7ef6c117867b616e9be1a90
Author: Elizabeth Thompson <es...@gmail.com>
AuthorDate: Tue Sep 1 16:45:15 2026 +0000

    fix(gsheets): catch JSONDecodeError in validate_parameters for malformed service_account_info
    
    When configuring a new Google Sheets connection, a user could paste
    malformed JSON into the "Service Account Credentials" field (a plausible
    typo or truncated paste). validate_parameters called json.loads on that
    string unguarded, so a raw json.JSONDecodeError propagated up through the
    validate_parameters command and API route to Flask's global exception
    handler, surfacing as an opaque 500 (GENERIC_BACKEND_ERROR) instead of the
    400 InvalidParametersError this flow is meant to return.
    
    Wrap the json.loads call in try/except json.JSONDecodeError and, on
    failure, append an INVALID_PAYLOAD_FORMAT_ERROR SupersetError to the errors
    list and return early, mirroring the existing early-return-on-fatal-error
    pattern in the same method. This turns the 500 into a proper 400 with a
    clear message that the credentials field is not valid JSON.
    
    Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
 superset/db_engine_specs/gsheets.py              | 17 ++++++++++++-
 tests/unit_tests/db_engine_specs/test_gsheets.py | 31 ++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/superset/db_engine_specs/gsheets.py b/superset/db_engine_specs/gsheets.py
index c932299f090..7fd1ac1156b 100644
--- a/superset/db_engine_specs/gsheets.py
+++ b/superset/db_engine_specs/gsheets.py
@@ -393,7 +393,22 @@ class GSheetsEngineSpec(ShillelaghEngineSpec):
         # On create the encrypted credentials are a string,
         # at all other times they are a dict
         if isinstance(encrypted_credentials, str):
-            encrypted_credentials = json.loads(encrypted_credentials)
+            try:
+                encrypted_credentials = json.loads(encrypted_credentials)
+            except json.JSONDecodeError:
+                errors.append(
+                    SupersetError(
+                        message=(
+                            "The service account credentials are not valid JSON. "
+                            "Please check that the field contains a valid service "
+                            "account key."
+                        ),
+                        error_type=SupersetErrorType.INVALID_PAYLOAD_FORMAT_ERROR,
+                        level=ErrorLevel.ERROR,
+                        extra={"invalid": ["service_account_info"]},
+                    ),
+                )
+                return errors
 
         # We need a subject in case domain wide delegation is set, otherwise the
         # check will fail. This means that the admin will be able to add sheets
diff --git a/tests/unit_tests/db_engine_specs/test_gsheets.py b/tests/unit_tests/db_engine_specs/test_gsheets.py
index fc77cf57732..4a156a0f5d6 100644
--- a/tests/unit_tests/db_engine_specs/test_gsheets.py
+++ b/tests/unit_tests/db_engine_specs/test_gsheets.py
@@ -110,6 +110,37 @@ def test_validate_parameters_no_catalog(mocker: MockerFixture) -> None:
     ]
 
 
+def test_validate_parameters_malformed_credentials(mocker: MockerFixture) -> None:
+    from superset.db_engine_specs.gsheets import (
+        GSheetsEngineSpec,
+        GSheetsPropertiesType,
+    )
+
+    g = mocker.patch("superset.db_engine_specs.gsheets.g")
+    g.user.email = "admin@example.org"
+
+    properties: GSheetsPropertiesType = {
+        "parameters": {
+            "service_account_info": "{not valid json",
+            "catalog": {},
+        },
+        "catalog": {},
+    }
+    errors = GSheetsEngineSpec.validate_parameters(properties)
+    assert errors == [
+        SupersetError(
+            message=(
+                "The service account credentials are not valid JSON. "
+                "Please check that the field contains a valid service "
+                "account key."
+            ),
+            error_type=SupersetErrorType.INVALID_PAYLOAD_FORMAT_ERROR,
+            level=ErrorLevel.ERROR,
+            extra={"invalid": ["service_account_info"]},
+        ),
+    ]
+
+
 def test_validate_parameters_simple_with_in_root_catalog(mocker: MockerFixture) -> None:
     from superset.db_engine_specs.gsheets import (
         GSheetsEngineSpec,