Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tags features flag on base models #23548

Merged
merged 12 commits into from
Apr 4, 2023
15 changes: 7 additions & 8 deletions superset/models/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 7 additions & 8 deletions superset/models/slice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
17 changes: 8 additions & 9 deletions superset/models/sql_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
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,
Expand Down Expand Up @@ -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 = [
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,7 @@ def test_get_chart(self):
],
"params": None,
"slice_name": "title",
"tags": [],
"viz_type": None,
"query_context": None,
"is_managed_externally": False,
Expand Down
1 change: 1 addition & 0 deletions tests/integration_tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ def test_get_dashboard(self):
"published": False,
"url": "/superset/dashboard/slug1/",
"slug": "slug1",
"tags": [],
"thumbnail_url": dashboard.thumbnail_url,
"is_managed_externally": False,
}
Expand Down
5 changes: 3 additions & 2 deletions tests/integration_tests/tags/dao_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def create_tags(self):
)
)
yield tags
db.session.commit()

@pytest.fixture()
def create_tagged_objects(self):
Expand Down Expand Up @@ -121,8 +120,8 @@ def create_tagged_objects(self):
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")
Expand Down Expand Up @@ -297,3 +296,5 @@ def test_delete_tagged_object(self):
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()
1 change: 1 addition & 0 deletions tests/integration_tests/tasks/async_queries_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
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


Expand Down