apache/superset · warning · TagNotFoundError

Tag not found.

Error message

Tag not found.

What it means

Raised by TagDAO.add_user_favorite_tag when TagDAO.find_by_id(tag_id) returns nothing — the favorite feature cannot favorite a nonexistent tag. It is the TagNotFoundError from superset.tags/commands (a CommandException), distinct from the tag.py DAO-level NoResultFound messages used for name lookups. The check order is user first, then tag, so a valid user plus a bad id lands here.

Source

Thrown at superset/daos/tag.py:277

        return TagDAO.get_tagged_objects_by_tag_ids(tag_ids, obj_types)

    @staticmethod
    def favorite_tag_by_id_for_current_user(  # pylint: disable=invalid-name
        tag_id: int,
    ) -> None:
        """
        Marks a specific tag as a favorite for the current user.

        :param tag_id: The id of the tag that is to be marked as favorite
        """

        tag = TagDAO.find_by_id(tag_id)
        user = g.user

        if not user:
            raise MissingUserContextException(message="User doesn't exist")
        if not tag:
            raise TagNotFoundError()

        tag.users_favorited.append(user)

    @staticmethod
    def remove_user_favorite_tag(tag_id: int) -> None:
        """
        Removes a tag from the current user's favorite tags.

        :param tag_id: The id of the tag that is to be removed from the favorite tags
        """
        tag = TagDAO.find_by_id(tag_id)
        user = g.user

        if not user:
            raise MissingUserContextException(message="User doesn't exist")
        if not tag:
            raise TagNotFoundError()

View on GitHub (pinned to f4587218dd)

Solutions

  1. Re-fetch the tag list and use a current tag_id.
  2. Catch TagNotFoundError and refresh/skip gracefully in the UI.
  3. Prefer resolving tags by name in scripts, then favorite by the freshly looked-up id.
  4. Ensure the delete-tag flow also clears client-side favorite state.

Example fix

# before
TagDAO.add_user_favorite_tag(1234)  # deleted tag -> TagNotFoundError

# after
tag = TagDAO.find_by_id(tag_id)
if tag:
    TagDAO.add_user_favorite_tag(tag_id)
else:
    refresh_tag_list()  # resync ids before favoriting
Defensive patterns

Strategy: validation

Validate before calling

from superset.daos.tag import TagDAO

def tag_id_exists(tag_id: int) -> bool:
    return TagDAO.find_by_id(tag_id) is not None

Try / catch

from superset.tags.exceptions import TagNotFoundError
try:
    TagDAO.add_user_favorite_tag(tag_id)
except TagNotFoundError:
    refresh_tag_list()  # ids are stale; re-resolve and let the user retry

Prevention

When it happens

Trigger: POST favorite-tag with an id of a deleted tag; integer id of a tag from another environment after metadata restore; typos in hand-crafted API payloads; race where the tag is deleted between the client listing tags and favoriting.

Common situations: Stale tag lists in the UI after another user deletes tags; scripts replaying recorded ids; environments rebuilt from dumps where tag ids shifted.

Related errors


AI-assisted analysis of apache/superset@f4587218dd (2026-08-14). Data as JSON: /api/errors/0658decf40fa48cc. Report an issue: GitHub.