You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by va...@apache.org on 2026/04/30 17:17:02 UTC
(superset) branch oauth2-fixes created (now b1be68fffba)
This is an automated email from the ASF dual-hosted git repository.
Vitor-Avila pushed a change to branch oauth2-fixes
in repository https://gitbox.apache.org/repos/asf/superset.git
at b1be68fffba fix(GSheets OAuth2): Re-add UnauthenticatedError
This branch includes the following new commits:
new b1be68fffba fix(GSheets OAuth2): Re-add UnauthenticatedError
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 OAuth2): Re-add UnauthenticatedError
Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
Vitor-Avila pushed a commit to branch oauth2-fixes
in repository https://gitbox.apache.org/repos/asf/superset.git
commit b1be68fffba094ae45762060fa5c210cdc0a36b9
Author: Vitor Avila <vi...@gmail.com>
AuthorDate: Thu Apr 30 14:16:15 2026 -0300
fix(GSheets OAuth2): Re-add UnauthenticatedError
---
superset/db_engine_specs/gsheets.py | 2 ++
tests/unit_tests/db_engine_specs/test_gsheets.py | 31 ++++++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/superset/db_engine_specs/gsheets.py b/superset/db_engine_specs/gsheets.py
index 4874102c903..d184d05341b 100644
--- a/superset/db_engine_specs/gsheets.py
+++ b/superset/db_engine_specs/gsheets.py
@@ -31,6 +31,7 @@ from marshmallow import fields, Schema
from marshmallow.exceptions import ValidationError
from requests import Session
from shillelagh.adapters.api.gsheets.lib import SCOPES
+from shillelagh.exceptions import UnauthenticatedError
from sqlalchemy.engine import create_engine
from sqlalchemy.engine.reflection import Inspector
from sqlalchemy.engine.url import URL
@@ -151,6 +152,7 @@ class GSheetsEngineSpec(ShillelaghEngineSpec):
"https://accounts.google.com/o/oauth2/v2/auth"
)
oauth2_token_request_uri = "https://oauth2.googleapis.com/token" # noqa: S105
+ oauth2_exception = UnauthenticatedError
@classmethod
def get_oauth2_authorization_uri(
diff --git a/tests/unit_tests/db_engine_specs/test_gsheets.py b/tests/unit_tests/db_engine_specs/test_gsheets.py
index 77f27344858..add5754a9c6 100644
--- a/tests/unit_tests/db_engine_specs/test_gsheets.py
+++ b/tests/unit_tests/db_engine_specs/test_gsheets.py
@@ -24,6 +24,7 @@ import pandas as pd
import pytest
from pytest_mock import MockerFixture
from requests.exceptions import HTTPError
+from shillelagh.exceptions import UnauthenticatedError
from sqlalchemy.engine.url import make_url
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
@@ -789,6 +790,36 @@ def test_needs_oauth2_with_other_error(mocker: MockerFixture) -> None:
assert GSheetsEngineSpec.needs_oauth2(ex) is False
+def test_needs_oauth2_with_shillelagh_unauthenticated_error(
+ mocker: MockerFixture,
+) -> None:
+ """
+ Test that needs_oauth2 returns True when UnauthenticatedError is raised.
+ """
+ from superset.db_engine_specs.gsheets import GSheetsEngineSpec
+
+ g = mocker.patch("superset.db_engine_specs.gsheets.g")
+ g.user = mocker.MagicMock()
+
+ ex = UnauthenticatedError("Token has been revoked")
+ assert GSheetsEngineSpec.needs_oauth2(ex) is True
+
+
+def test_needs_oauth2_with_unrelated_exception_type(
+ mocker: MockerFixture,
+) -> None:
+ """
+ Test that an unrelated exception type (with no matching message) returns
+ False.
+ """
+ from superset.db_engine_specs.gsheets import GSheetsEngineSpec
+
+ g = mocker.patch("superset.db_engine_specs.gsheets.g")
+ g.user = mocker.MagicMock()
+
+ assert GSheetsEngineSpec.needs_oauth2(ValueError("unrelated")) is False
+
+
def test_get_oauth2_fresh_token_success(
mocker: MockerFixture,
oauth2_config: OAuth2ClientConfig,