From 7891cea7f75a252e3f3cf83febb835645b41ea30 Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Mon, 22 May 2023 14:09:12 -0400 Subject: [PATCH] fix: always allow tags to be returned via the API (#24060) --- superset/charts/api.py | 17 ++++++++--------- superset/charts/schemas.py | 4 +++- superset/dashboards/schemas.py | 4 +++- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/superset/charts/api.py b/superset/charts/api.py index 2c50a8d163cb8..9c1756b2a537c 100644 --- a/superset/charts/api.py +++ b/superset/charts/api.py @@ -143,9 +143,10 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "viz_type", "query_context", "is_managed_externally", + "tags.id", + "tags.name", + "tags.type", ] - if is_feature_enabled("TAGGING_SYSTEM"): - show_columns += ["tags.id", "tags.name", "tags.type"] show_select_columns = show_columns + ["table.id"] list_columns = [ @@ -192,9 +193,10 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "thumbnail_url", "url", "viz_type", + "tags.id", + "tags.name", + "tags.type", ] - if is_feature_enabled("TAGGING_SYSTEM"): - list_columns += ["tags.id", "tags.name", "tags.type"] list_select_columns = list_columns + ["changed_by_fk", "changed_on"] order_columns = [ "changed_by.first_name", @@ -222,9 +224,8 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "dashboards", "slice_name", "viz_type", + "tags", ] - if is_feature_enabled("TAGGING_SYSTEM"): - search_columns += ["tags"] base_order = ("changed_on", "desc") base_filters = [["id", ChartFilter, lambda: []]] search_filters = { @@ -235,10 +236,8 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: ], "slice_name": [ChartAllTextFilter], "created_by": [ChartHasCreatedByFilter, ChartCreatedByMeFilter], + "tags": [ChartTagFilter], } - if is_feature_enabled("TAGGING_SYSTEM"): - search_filters["tags"] = [ChartTagFilter] - # Will just affect _info endpoint edit_columns = ["slice_name"] add_columns = edit_columns diff --git a/superset/charts/schemas.py b/superset/charts/schemas.py index e70dbad476e69..44252ef06f9aa 100644 --- a/superset/charts/schemas.py +++ b/superset/charts/schemas.py @@ -28,6 +28,7 @@ from superset import app from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType from superset.db_engine_specs.base import builtin_time_grains +from superset.tags.models import TagTypes from superset.utils import pandas_postprocessing, schema as utils from superset.utils.core import ( AnnotationType, @@ -152,7 +153,7 @@ class TagSchema(Schema): id = fields.Int() name = fields.String() - type = fields.String() + type = EnumField(TagTypes, by_value=True) class ChartEntityResponseSchema(Schema): @@ -290,6 +291,7 @@ class ChartPutSchema(Schema): ) is_managed_externally = fields.Boolean(allow_none=True, dump_default=False) external_url = fields.String(allow_none=True) + tags = fields.Nested(TagSchema, many=True) class ChartGetDatasourceObjectDataResponseSchema(Schema): diff --git a/superset/dashboards/schemas.py b/superset/dashboards/schemas.py index 32558de4ab014..ab93e4130f87a 100644 --- a/superset/dashboards/schemas.py +++ b/superset/dashboards/schemas.py @@ -20,8 +20,10 @@ from marshmallow import fields, post_load, pre_load, Schema from marshmallow.validate import Length, ValidationError +from marshmallow_enum import EnumField from superset.exceptions import SupersetException +from superset.tags.models import TagTypes from superset.utils import core as utils get_delete_ids_schema = {"type": "array", "items": {"type": "integer"}} @@ -172,7 +174,7 @@ class RolesSchema(Schema): class TagSchema(Schema): id = fields.Int() name = fields.String() - type = fields.String() + type = EnumField(TagTypes, by_value=True) class DashboardGetResponseSchema(Schema):