From 9ca53b89052845c0d8f379b1c2286aea8b4e975e Mon Sep 17 00:00:00 2001 From: Ville Brofeldt <33317356+villebro@users.noreply.github.com> Date: Tue, 3 May 2022 07:19:36 +0300 Subject: [PATCH] fix(sqla): replace custom dttm type with literal_column (#19917) (cherry picked from commit 99f1f9ec610159db650081d9691835eea0f42b88) --- superset/connectors/base/models.py | 31 ++++++--- superset/connectors/druid/models.py | 2 +- superset/connectors/sqla/models.py | 20 ++++-- superset/db_engine_specs/athena.py | 4 +- superset/db_engine_specs/base.py | 9 +-- superset/db_engine_specs/presto.py | 6 +- superset/db_engine_specs/trino.py | 4 +- superset/models/sql_types/base.py | 65 ------------------- .../db_engine_specs/presto_tests.py | 6 +- .../db_engine_specs/trino_tests.py | 4 +- tests/integration_tests/model_tests.py | 24 +------ .../unit_tests/db_engine_specs/test_athena.py | 9 +-- .../unit_tests/db_engine_specs/test_presto.py | 8 +-- .../unit_tests/db_engine_specs/test_trino.py | 8 +-- 14 files changed, 63 insertions(+), 137 deletions(-) delete mode 100644 superset/models/sql_types/base.py diff --git a/superset/connectors/base/models.py b/superset/connectors/base/models.py index 9aacb0dc8c641..7595141500a03 100644 --- a/superset/connectors/base/models.py +++ b/superset/connectors/base/models.py @@ -14,15 +14,18 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. +from __future__ import annotations + import json from datetime import datetime from enum import Enum -from typing import Any, Dict, Hashable, List, Optional, Set, Type, Union +from typing import Any, Dict, Hashable, List, Optional, Set, Type, TYPE_CHECKING, Union from flask_appbuilder.security.sqla.models import User from sqlalchemy import and_, Boolean, Column, Integer, String, Text from sqlalchemy.ext.declarative import declared_attr from sqlalchemy.orm import foreign, Query, relationship, RelationshipProperty, Session +from sqlalchemy.sql import literal_column from superset import is_feature_enabled, security_manager from superset.constants import EMPTY_STRING, NULL_STRING @@ -33,6 +36,9 @@ from superset.utils import core as utils from superset.utils.core import GenericDataType +if TYPE_CHECKING: + from superset.db_engine_specs.base import BaseEngineSpec + METRIC_FORM_DATA_PARAMS = [ "metric", "metric_2", @@ -387,25 +393,34 @@ def data_for_slices( # pylint: disable=too-many-locals return data @staticmethod - def filter_values_handler( + def filter_values_handler( # pylint: disable=too-many-arguments values: Optional[FilterValues], - target_column_type: utils.GenericDataType, + target_generic_type: GenericDataType, + target_native_type: Optional[str] = None, is_list_target: bool = False, + db_engine_spec: Optional[Type[BaseEngineSpec]] = None, + db_extra: Optional[Dict[str, Any]] = None, ) -> Optional[FilterValues]: if values is None: return None def handle_single_value(value: Optional[FilterValue]) -> Optional[FilterValue]: - # backward compatibility with previous