diff --git a/superset/commands/chart/update.py b/superset/commands/chart/update.py index d6b212d5ce861..2d06ef70d8654 100644 --- a/superset/commands/chart/update.py +++ b/superset/commands/chart/update.py @@ -63,7 +63,7 @@ def run(self) -> Model: # Update tags if (tags := self._properties.pop("tags", None)) is not None: - update_tags(ObjectType.chart, self._model.id, self._model.tags, tags) + update_tags(ObjectType.CHART, self._model.id, self._model.tags, tags) if self._properties.get("query_context_generation") is None: self._properties["last_saved_at"] = datetime.now() @@ -79,6 +79,7 @@ def validate(self) -> None: # Validate if datasource_id is provided datasource_type is required datasource_id = self._properties.get("datasource_id") + datasource_type: str | None = None if datasource_id is not None: datasource_type = self._properties.get("datasource_type", "") if not datasource_type: @@ -106,7 +107,7 @@ def validate(self) -> None: # validate tags try: - validate_tags(ObjectType.chart, self._model.tags, tag_ids) + validate_tags(ObjectType.CHART, self._model.tags, tag_ids) except ValidationError as ex: exceptions.append(ex) diff --git a/superset/commands/dashboard/update.py b/superset/commands/dashboard/update.py index 15f5e5b5841b8..22601ee073b87 100644 --- a/superset/commands/dashboard/update.py +++ b/superset/commands/dashboard/update.py @@ -60,7 +60,7 @@ def run(self) -> Model: # Update tags if (tags := self._properties.pop("tags", None)) is not None: - update_tags(ObjectType.dashboard, self._model.id, self._model.tags, tags) + update_tags(ObjectType.DASHBOARD, self._model.id, self._model.tags, tags) dashboard = DashboardDAO.update(self._model, self._properties) if self._properties.get("json_metadata"): @@ -103,7 +103,7 @@ def validate(self) -> None: # validate tags try: - validate_tags(ObjectType.dashboard, self._model.tags, tag_ids) + validate_tags(ObjectType.DASHBOARD, self._model.tags, tag_ids) except ValidationError as ex: exceptions.append(ex) diff --git a/superset/commands/utils.py b/superset/commands/utils.py index 7486d657adc60..276d4c8239bcb 100644 --- a/superset/commands/utils.py +++ b/superset/commands/utils.py @@ -130,7 +130,7 @@ def validate_tags( return # No changes in the list - current_custom_tags = [tag.id for tag in current_tags if tag.type == TagType.custom] + current_custom_tags = [tag.id for tag in current_tags if tag.type == TagType.CUSTOM] if Counter(current_custom_tags) == Counter(new_tag_ids): return @@ -169,9 +169,9 @@ def update_tags( :param new_tag_ids: list of tags specified in the update payload """ - current_custom_tags = [tag for tag in current_tags if tag.type == TagType.custom] + current_custom_tags = [tag for tag in current_tags if tag.type == TagType.CUSTOM] current_custom_tag_ids = [ - tag.id for tag in current_tags if tag.type == TagType.custom + tag.id for tag in current_tags if tag.type == TagType.CUSTOM ] tags_to_delete = [tag for tag in current_custom_tags if tag.id not in new_tag_ids] diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index fc00dd3bc2955..4c5430e99195a 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -218,7 +218,7 @@ def create_chart_with_tag(self, create_custom_tags): # noqa: F811 tag = db.session.query(Tag).filter(Tag.name == "first_tag").first() tag_association = TaggedObject( object_id=chart.id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tag, ) @@ -263,22 +263,22 @@ def create_charts_some_with_tags(self, create_custom_tags): # noqa: F811 tag_associations = [ TaggedObject( object_id=charts[0].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["first_tag"], ), TaggedObject( object_id=charts[1].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["second_tag"], ), TaggedObject( object_id=charts[2].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["first_tag"], ), TaggedObject( object_id=charts[2].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["second_tag"], ), ] diff --git a/tests/integration_tests/dashboards/api_tests.py b/tests/integration_tests/dashboards/api_tests.py index 6c6e11c8969c3..47d0680c01fc3 100644 --- a/tests/integration_tests/dashboards/api_tests.py +++ b/tests/integration_tests/dashboards/api_tests.py @@ -194,7 +194,7 @@ def create_dashboard_with_tag(self, create_custom_tags): # noqa: F811 tag = db.session.query(Tag).filter(Tag.name == "first_tag").first() tag_association = TaggedObject( object_id=dashboard.id, - object_type=ObjectType.dashboard, + object_type=ObjectType.DASHBOARD, tag=tag, ) @@ -245,22 +245,22 @@ def create_dashboards_some_with_tags(self, create_custom_tags): # noqa: F811 tag_associations = [ TaggedObject( object_id=dashboards[0].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["first_tag"], ), TaggedObject( object_id=dashboards[1].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["second_tag"], ), TaggedObject( object_id=dashboards[2].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["first_tag"], ), TaggedObject( object_id=dashboards[2].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["second_tag"], ), ] diff --git a/tests/integration_tests/queries/saved_queries/api_tests.py b/tests/integration_tests/queries/saved_queries/api_tests.py index aa2c931104e4e..5341f798ae6ce 100644 --- a/tests/integration_tests/queries/saved_queries/api_tests.py +++ b/tests/integration_tests/queries/saved_queries/api_tests.py @@ -163,22 +163,22 @@ def create_saved_queries_some_with_tags(self, create_custom_tags): # noqa: F811 tag_associations = [ TaggedObject( object_id=queries[0].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["first_tag"], ), TaggedObject( object_id=queries[1].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["second_tag"], ), TaggedObject( object_id=queries[2].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["first_tag"], ), TaggedObject( object_id=queries[2].id, - object_type=ObjectType.chart, + object_type=ObjectType.CHART, tag=tags["second_tag"], ), ] diff --git a/tests/unit_tests/commands/test_utils.py b/tests/unit_tests/commands/test_utils.py index 810142d3d9591..071485c98247f 100644 --- a/tests/unit_tests/commands/test_utils.py +++ b/tests/unit_tests/commands/test_utils.py @@ -32,37 +32,37 @@ ) from superset.tags.models import ObjectType -OBJECT_TYPES = {ObjectType.chart, ObjectType.chart} +OBJECT_TYPES = {ObjectType.CHART, ObjectType.CHART} MOCK_TAGS = [ Tag( id=1, name="first", - type=TagType.custom, + type=TagType.CUSTOM, ), Tag( id=2, name="second", - type=TagType.custom, + type=TagType.CUSTOM, ), Tag( id=3, name="third", - type=TagType.custom, + type=TagType.CUSTOM, ), Tag( id=4, name="type:dashboard", - type=TagType.type, + type=TagType.TYPE, ), Tag( id=4, name="owner:1", - type=TagType.owner, + type=TagType.OWNER, ), Tag( id=4, name="avorited_by:2", - type=TagType.favorited_by, + type=TagType.FAVORITED_BY, ), ]