You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2024/09/10 16:15:10 UTC
(superset) branch master updated: chore: remove duplicate `_process_sql_expression` (#30213)
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new cddf1530da chore: remove duplicate `_process_sql_expression` (#30213)
cddf1530da is described below
commit cddf1530dadff48b4254ef4ba2b8e2403c1d133c
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue Sep 10 12:15:03 2024 -0400
chore: remove duplicate `_process_sql_expression` (#30213)
---
superset/connectors/sqla/models.py | 55 +++++++++++++-------------------------
1 file changed, 19 insertions(+), 36 deletions(-)
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index a70b860d2e..77243d41f8 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -83,7 +83,6 @@ from superset.db_engine_specs.base import BaseEngineSpec, TimestampExpression
from superset.exceptions import (
ColumnNotFoundException,
DatasetInvalidPermissionEvaluationException,
- QueryClauseValidationException,
QueryObjectValidationError,
SupersetErrorException,
SupersetErrorsException,
@@ -103,10 +102,9 @@ from superset.models.helpers import (
ExploreMixin,
ImportExportMixin,
QueryResult,
- validate_adhoc_subquery,
)
from superset.models.slice import Slice
-from superset.sql_parse import ParsedQuery, sanitize_clause, Table
+from superset.sql_parse import ParsedQuery, Table
from superset.superset_typing import (
AdhocColumn,
AdhocMetric,
@@ -1136,27 +1134,6 @@ sqlatable_user = DBTable(
)
-def _process_sql_expression(
- expression: str | None,
- database_id: int,
- schema: str,
- template_processor: BaseTemplateProcessor | None = None,
-) -> str | None:
- if template_processor and expression:
- expression = template_processor.process_template(expression)
- if expression:
- try:
- expression = validate_adhoc_subquery(
- expression,
- database_id,
- schema,
- )
- expression = sanitize_clause(expression)
- except (QueryClauseValidationException, SupersetSecurityException) as ex:
- raise QueryObjectValidationError(ex.message) from ex
- return expression
-
-
class SqlaTable(
Model,
BaseDatasource,
@@ -1552,12 +1529,15 @@ class SqlaTable(
sqla_column = column(column_name)
sqla_metric = self.sqla_aggregations[metric["aggregate"]](sqla_column)
elif expression_type == utils.AdhocMetricExpressionType.SQL:
- expression = _process_sql_expression(
- expression=metric["sqlExpression"],
- database_id=self.database_id,
- schema=self.schema,
- template_processor=template_processor,
- )
+ try:
+ expression = self._process_sql_expression(
+ expression=metric["sqlExpression"],
+ database_id=self.database_id,
+ schema=self.schema,
+ template_processor=template_processor,
+ )
+ except SupersetSecurityException as ex:
+ raise QueryObjectValidationError(ex.message) from ex
sqla_metric = literal_column(expression)
else:
raise QueryObjectValidationError("Adhoc metric expressionType is invalid")
@@ -1582,12 +1562,15 @@ class SqlaTable(
:rtype: sqlalchemy.sql.column
"""
label = utils.get_column_name(col)
- expression = _process_sql_expression(
- expression=col["sqlExpression"],
- database_id=self.database_id,
- schema=self.schema,
- template_processor=template_processor,
- )
+ try:
+ expression = self._process_sql_expression(
+ expression=col["sqlExpression"],
+ database_id=self.database_id,
+ schema=self.schema,
+ template_processor=template_processor,
+ )
+ except SupersetSecurityException as ex:
+ raise QueryObjectValidationError(ex.message) from ex
time_grain = col.get("timeGrain")
has_timegrain = col.get("columnType") == "BASE_AXIS" and time_grain
is_dttm = False