From a4d4084d081a4caab17c40ad3d2dd75b463b57ba Mon Sep 17 00:00:00 2001 From: "Hugh A. Miles II" Date: Tue, 4 Apr 2023 10:32:24 -0400 Subject: [PATCH] fix: tags features flag on base models (#23548) --- superset/models/dashboard.py | 15 +++++++-------- superset/models/slice.py | 15 +++++++-------- superset/models/sql_lab.py | 17 ++++++++--------- tests/integration_tests/charts/api_tests.py | 1 + tests/integration_tests/dashboards/api_tests.py | 1 + tests/integration_tests/tags/dao_tests.py | 5 +++-- .../tasks/async_queries_tests.py | 1 + 7 files changed, 28 insertions(+), 27 deletions(-) diff --git a/superset/models/dashboard.py b/superset/models/dashboard.py index d6dfe79d7..9292e1acd 100644 --- a/superset/models/dashboard.py +++ b/superset/models/dashboard.py @@ -149,14 +149,13 @@ class Dashboard(Model, AuditMixinNullable, ImportExportMixin): Slice, secondary=dashboard_slices, backref="dashboards" ) owners = relationship(security_manager.user_model, secondary=dashboard_user) - if is_feature_enabled("TAGGING_SYSTEM"): - tags = relationship( - "Tag", - secondary="tagged_object", - primaryjoin="and_(Dashboard.id == TaggedObject.object_id)", - secondaryjoin="and_(TaggedObject.tag_id == Tag.id, " - "TaggedObject.object_type == 'dashboard')", - ) + tags = relationship( + "Tag", + secondary="tagged_object", + primaryjoin="and_(Dashboard.id == TaggedObject.object_id)", + secondaryjoin="and_(TaggedObject.tag_id == Tag.id, " + "TaggedObject.object_type == 'dashboard')", + ) published = Column(Boolean, default=False) is_managed_externally = Column(Boolean, nullable=False, default=False) external_url = Column(Text, nullable=True) diff --git a/superset/models/slice.py b/superset/models/slice.py index 6bdd1bda6..cc975d263 100644 --- a/superset/models/slice.py +++ b/superset/models/slice.py @@ -96,14 +96,13 @@ class Slice( # pylint: disable=too-many-public-methods security_manager.user_model, foreign_keys=[last_saved_by_fk] ) owners = relationship(security_manager.user_model, secondary=slice_user) - if is_feature_enabled("TAGGING_SYSTEM"): - tags = relationship( - "Tag", - secondary="tagged_object", - primaryjoin="and_(Slice.id == TaggedObject.object_id)", - secondaryjoin="and_(TaggedObject.tag_id == Tag.id, " - "TaggedObject.object_type == 'chart')", - ) + tags = relationship( + "Tag", + secondary="tagged_object", + primaryjoin="and_(Slice.id == TaggedObject.object_id)", + secondaryjoin="and_(TaggedObject.tag_id == Tag.id, " + "TaggedObject.object_type == 'chart')", + ) table = relationship( "SqlaTable", foreign_keys=[datasource_id], diff --git a/superset/models/sql_lab.py b/superset/models/sql_lab.py index f12c8d6c4..3b5f171f4 100644 --- a/superset/models/sql_lab.py +++ b/superset/models/sql_lab.py @@ -42,7 +42,7 @@ from sqlalchemy import ( from sqlalchemy.engine.url import URL from sqlalchemy.orm import backref, relationship -from superset import is_feature_enabled, security_manager +from superset import security_manager from superset.jinja_context import BaseTemplateProcessor, get_template_processor from superset.models.helpers import ( AuditMixinNullable, @@ -366,14 +366,13 @@ class SavedQuery(Model, AuditMixinNullable, ExtraJSONMixin, ImportExportMixin): ) rows = Column(Integer, nullable=True) last_run = Column(DateTime, nullable=True) - if is_feature_enabled("TAGGING_SYSTEM"): - tags = relationship( - "Tag", - secondary="tagged_object", - primaryjoin="and_(SavedQuery.id == TaggedObject.object_id)", - secondaryjoin="and_(TaggedObject.tag_id == Tag.id, " - "TaggedObject.object_type == 'saved_query')", - ) + tags = relationship( + "Tag", + secondary="tagged_object", + primaryjoin="and_(SavedQuery.id == TaggedObject.object_id)", + secondaryjoin="and_(TaggedObject.tag_id == Tag.id, " + "TaggedObject.object_type == 'saved_query')", + ) export_parent = "database" export_fields = [ diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index 62da324d5..5a261fb55 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -830,6 +830,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin): ], "params": None, "slice_name": "title", + "tags": [], "viz_type": None, "query_context": None, "is_managed_externally": False, diff --git a/tests/integration_tests/dashboards/api_tests.py b/tests/integration_tests/dashboards/api_tests.py index 6abc649b9..29be38bc1 100644 --- a/tests/integration_tests/dashboards/api_tests.py +++ b/tests/integration_tests/dashboards/api_tests.py @@ -434,6 +434,7 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi "published": False, "url": "/superset/dashboard/slug1/", "slug": "slug1", + "tags": [], "thumbnail_url": dashboard.thumbnail_url, "is_managed_externally": False, } diff --git a/tests/integration_tests/tags/dao_tests.py b/tests/integration_tests/tags/dao_tests.py index 0234b2c8c..f46abaa72 100644 --- a/tests/integration_tests/tags/dao_tests.py +++ b/tests/integration_tests/tags/dao_tests.py @@ -88,7 +88,6 @@ class TestTagsDAO(SupersetTestCase): ) ) yield tags - db.session.commit() @pytest.fixture() def create_tagged_objects(self): @@ -121,8 +120,8 @@ class TestTagsDAO(SupersetTestCase): tag_id=tag.id, ) ) + yield tagged_objects - db.session.commit() @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices") @pytest.mark.usefixtures("with_tagging_system_feature") @@ -297,3 +296,5 @@ class TestTagsDAO(SupersetTestCase): def test_validate_tag_name(self): assert TagDAO.validate_tag_name("example_tag_name") is True assert TagDAO.validate_tag_name("invalid:tag_name") is False + db.session.query(TaggedObject).delete() + db.session.query(Tag).delete() diff --git a/tests/integration_tests/tasks/async_queries_tests.py b/tests/integration_tests/tasks/async_queries_tests.py index 20d0f39ee..9e5c9657c 100644 --- a/tests/integration_tests/tasks/async_queries_tests.py +++ b/tests/integration_tests/tasks/async_queries_tests.py @@ -38,6 +38,7 @@ from tests.integration_tests.fixtures.birth_names_dashboard import ( load_birth_names_data, ) from tests.integration_tests.fixtures.query_context import get_query_context +from tests.integration_tests.fixtures.tags import with_tagging_system_feature from tests.integration_tests.test_app import app