You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/09/16 15:53:33 UTC

(superset) branch fix/tag-system-filter-and-rename updated: fix(tags): rename TagDAO.get_by_name to get_or_create_by_name

This is an automated email from the ASF dual-hosted git repository.

rusackas pushed a commit to branch fix/tag-system-filter-and-rename
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/fix/tag-system-filter-and-rename by this push:
     new 5a6d335db92 fix(tags): rename TagDAO.get_by_name to get_or_create_by_name
5a6d335db92 is described below

commit 5a6d335db9257ffb2d41b437971a4aa2a856349f
Author: rusackas <ev...@rusackas.com>
AuthorDate: Wed Sep 16 08:53:09 2026 -0700

    fix(tags): rename TagDAO.get_by_name to get_or_create_by_name
    
    Addresses review feedback on #35541: the old name and docstring
    contradicted each other ("none otherwise" followed by an "important!"
    note that a tag would be created), which is confusing for callers.
    
    Co-Authored-By: Evan Rusackas <ev...@preset.io>
    Co-Authored-By: Claude Opus 4.8 <no...@anthropic.com>
---
 superset/commands/tag/create.py           | 2 +-
 superset/daos/tag.py                      | 7 +++----
 tests/integration_tests/tags/dao_tests.py | 6 +++---
 tests/unit_tests/dao/tag_test.py          | 2 +-
 4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/superset/commands/tag/create.py b/superset/commands/tag/create.py
index 0c45d154e4e..5fb2a78dad4 100644
--- a/superset/commands/tag/create.py
+++ b/superset/commands/tag/create.py
@@ -135,7 +135,7 @@ class CreateCustomTagWithRelationshipsCommand(CreateMixin, BaseCommand):
         self.validate()
 
         tag_name = self._properties["name"]
-        tag = TagDAO.get_by_name(tag_name.strip(), TagType.custom)
+        tag = TagDAO.get_or_create_by_name(tag_name.strip(), TagType.custom)
         TagDAO.create_tag_relationship(
             objects_to_tag=self._properties.get("objects_to_tag", []),
             tag=tag,
diff --git a/superset/daos/tag.py b/superset/daos/tag.py
index ad08c25997e..e09bac169bb 100644
--- a/superset/daos/tag.py
+++ b/superset/daos/tag.py
@@ -53,7 +53,7 @@ class TagDAO(BaseDAO[Tag]):
 
         for name in clean_tag_names:
             type_ = TagType.custom
-            tag = TagDAO.get_by_name(name, type_)
+            tag = TagDAO.get_or_create_by_name(name, type_)
 
             # Check if the association already exists
             existing_tagged_object = (
@@ -111,10 +111,9 @@ class TagDAO(BaseDAO[Tag]):
             db.session.delete(tag)
 
     @staticmethod
-    def get_by_name(name: str, type_: TagType = TagType.custom) -> Tag:
+    def get_or_create_by_name(name: str, type_: TagType = TagType.custom) -> Tag:
         """
-        returns a tag if one exists by that name, none otherwise.
-        important!: Creates a tag by that name if the tag is not found.
+        Returns a tag by that name, creating it first if it doesn't exist yet.
         """
         tag = (
             db.session.query(Tag)
diff --git a/tests/integration_tests/tags/dao_tests.py b/tests/integration_tests/tags/dao_tests.py
index 6273799a379..c891e7d9a56 100644
--- a/tests/integration_tests/tags/dao_tests.py
+++ b/tests/integration_tests/tags/dao_tests.py
@@ -282,12 +282,12 @@ class TestTagsDAO(SupersetTestCase):
     @pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
     @pytest.mark.usefixtures("with_tagging_system_feature")
     @pytest.mark.usefixtures("create_tagged_objects")
-    def test_get_by_name(self):
+    def test_get_or_create_by_name(self):
         # test tag can be found
-        tag = TagDAO.get_by_name("example_tag_1")
+        tag = TagDAO.get_or_create_by_name("example_tag_1")
         assert tag is not None
         # tag that doesnt exist is added
-        tag = TagDAO.get_by_name("invalid_tag_1")
+        tag = TagDAO.get_or_create_by_name("invalid_tag_1")
         assert tag is not None
         # tag was created
         tag = db.session.query(Tag).filter(Tag.name == "invalid_tag_1").first()
diff --git a/tests/unit_tests/dao/tag_test.py b/tests/unit_tests/dao/tag_test.py
index c1ca0ee5164..34f7868bd85 100644
--- a/tests/unit_tests/dao/tag_test.py
+++ b/tests/unit_tests/dao/tag_test.py
@@ -155,7 +155,7 @@ def test_create_tag_relationship(mocker):
     ]
 
     # Call the function
-    tag = TagDAO.get_by_name("test_tag")
+    tag = TagDAO.get_or_create_by_name("test_tag")
     TagDAO.create_tag_relationship(objects_to_tag, tag)
 
     # Verify that the correct number of TaggedObjects are added to the session