fix(sqllab): keep saved-query list working when Jinja dataset(id) references a deleted dataset

When a saved query contains a Jinja macro such as `{{ dataset(id) }}` and the
referenced dataset is later deleted, `process_jinja_sql` raises
`DatasetNotFoundError` while computing the `sql_tables` field. That exception
was not caught by `SqlTablesMixin.sql_tables`, so the entire saved-query list
endpoint failed with "Dataset ID not found", hiding every saved query from
the user and preventing them from deleting the broken one (#32771).

Treat any `SupersetException` raised during table extraction the same way as
existing parse/security/template errors: log a warning and return an empty
list so the rest of the row can still be serialized.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Evan Rusackas
2026-04-27 11:49:15 -07:00
parent 5fe3a1c2cd
commit cdc1397033
2 changed files with 24 additions and 2 deletions

View File

@@ -52,7 +52,11 @@ from superset_core.queries.models import (
)
from superset import security_manager
from superset.exceptions import SupersetParseError, SupersetSecurityException
from superset.exceptions import (
SupersetException,
SupersetParseError,
SupersetSecurityException,
)
from superset.explorables.base import TimeGrainDict
from superset.jinja_context import BaseTemplateProcessor, get_template_processor
from superset.models.helpers import (
@@ -98,6 +102,14 @@ class SqlTablesMixin: # pylint: disable=too-few-public-methods
)
except (SupersetSecurityException, SupersetParseError, TemplateError):
return []
except SupersetException as ex:
# Jinja macros such as ``{{ dataset(id) }}`` or ``{{ metric(...) }}``
# may reference resources that no longer exist (e.g. a deleted
# dataset). Surfacing the failure here would break list endpoints
# that include ``sql_tables`` in their payload, hiding every saved
# query from the user. Treat it as a parse failure instead.
logger.warning("Unable to extract tables from SQL via Jinja: %s", ex)
return []
class Query(