Skip to content

Commit

Permalink
change migration order
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh committed Jul 25, 2023
1 parent 0e448ff commit 8c5772b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 17 deletions.
8 changes: 3 additions & 5 deletions superset/daos/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,8 @@ def favorite_tag_by_id_for_current_user( # pylint: disable=invalid-name
if not tag:
raise TagNotFoundError()

if tag and user:
tag.users_favorited.append(user)
db.session.commit()
tag.users_favorited.append(user)
db.session.commit()

@staticmethod
def remove_user_favorite_tag(tag_id: int) -> None:
Expand Down Expand Up @@ -329,8 +328,7 @@ def remove_user_favorite_tag(tag_id: int) -> None:
if not tag:
raise TagNotFoundError()

if tag and user:
tag.users_favorited.remove(user)
tag.users_favorited.remove(user)

# Commit to save the changes
db.session.commit()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@
"""create_user_favorite_table
Revision ID: e0f6f91c2055
Revises: 863adcf72773
Revises: a23c6f8b1280
Create Date: 2023-07-12 20:34:57.553981
"""

# revision identifiers, used by Alembic.
revision = "e0f6f91c2055"
down_revision = "863adcf72773"
down_revision = "a23c6f8b1280"

import sqlalchemy as sa
from alembic import op
Expand Down
31 changes: 21 additions & 10 deletions superset/tags/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.daos.tag import TagDAO
from superset.exceptions import UserNotFound
from superset.extensions import event_logger
from superset.tags.commands.create import CreateCustomTagCommand
from superset.tags.commands.delete import DeleteTaggedObjectCommand, DeleteTagsCommand
Expand Down Expand Up @@ -427,14 +428,19 @@ def favorite_status(self, **kwargs: Any) -> Response:
500:
$ref: '#/components/responses/500'
"""
requested_ids = kwargs["rison"]
tags = TagDAO.find_by_ids(requested_ids)
users_favorited_tags = TagDAO.favorited_ids(tags)
res = [
{"id": request_id, "value": request_id in users_favorited_tags}
for request_id in requested_ids
]
return self.response(200, result=res)
try:
requested_ids = kwargs["rison"]
tags = TagDAO.find_by_ids(requested_ids)
users_favorited_tags = TagDAO.favorited_ids(tags)
res = [
{"id": request_id, "value": request_id in users_favorited_tags}
for request_id in requested_ids
]
return self.response(200, result=res)
except TagNotFoundError:
return self.response_404()
except UserNotFound as ex:
return self.response_422(message=str(ex))

@expose("/<pk>/favorites/", methods=("POST",))
@protect()
Expand Down Expand Up @@ -473,8 +479,13 @@ def add_favorite(self, pk: int) -> Response:
500:
$ref: '#/components/responses/500'
"""
TagDAO.favorite_tag_by_id_for_current_user(pk)
return self.response(200, result="OK")
try:
TagDAO.favorite_tag_by_id_for_current_user(pk)
return self.response(200, result="OK")
except TagNotFoundError:
return self.response_404()
except UserNotFound as ex:
return self.response_422(message=str(ex))

@expose("/<pk>/favorites/", methods=("DELETE",))
@protect()
Expand Down

0 comments on commit 8c5772b

Please sign in to comment.