mikebridge commented on code in PR #40128: URL: https://github.com/apache/superset/pull/40128#discussion_r3337362815
########## superset/commands/dashboard/restore.py: ########## @@ -0,0 +1,84 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +"""Command to restore a soft-deleted dashboard.""" + +import logging + +from superset.commands.dashboard.exceptions import ( + DashboardForbiddenError, + DashboardNotFoundError, + DashboardRestoreFailedError, + DashboardSlugConflictError, +) +from superset.commands.restore import BaseRestoreCommand +from superset.daos.dashboard import DashboardDAO +from superset.extensions import db +from superset.models.dashboard import Dashboard + +logger = logging.getLogger(__name__) + + +class RestoreDashboardCommand(BaseRestoreCommand[Dashboard]): + """Restore a soft-deleted dashboard by clearing its ``deleted_at`` field. + + Most behaviour is inherited from ``BaseRestoreCommand``. The override + here adds the slug-conflict check: with the partial unique index on Review Comment: This is one potential solution out of many, but I wanted to try to find a straightforward way of preventing a user from having to somehow edit a deleted dashboard to fix a conflict in the slug. (e.g. the bad path might be: user deletes item with slug "test", then creates a new "test" dashboard to replace it, tries to save it, but gets an error and has to set the slug to "test-temp", save it for real, then find the conflicting deleted dashboard, restore it, edit it to something like "test-deleted", soft-delete it again, then go back to the new one.). A partial unique index avoids the problem until someone wants to restore a dashboard with a conflict, which will be less likely. But it's only in mysql8 and postgres. I'm interested in any feedback. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
