mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
fix: prevent ForeignKeyViolation error on delete (#23414)
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from typing import Optional
|
||||
from typing import cast, Optional
|
||||
|
||||
from flask_appbuilder.models.sqla import Model
|
||||
from flask_babel import lazy_gettext as _
|
||||
@@ -45,8 +45,13 @@ class DeleteChartCommand(BaseCommand):
|
||||
|
||||
def run(self) -> Model:
|
||||
self.validate()
|
||||
self._model = cast(Slice, self._model)
|
||||
try:
|
||||
Dashboard.clear_cache_for_slice(slice_id=self._model_id)
|
||||
# Even though SQLAlchemy should in theory delete rows from the association
|
||||
# table, sporadically Superset will error because the rows are not deleted.
|
||||
# Let's do it manually here to prevent the error.
|
||||
self._model.owners = []
|
||||
chart = ChartDAO.delete(self._model)
|
||||
except DAODeleteFailedError as ex:
|
||||
logger.exception(ex.exception)
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import logging
|
||||
from typing import Optional
|
||||
from typing import cast, Optional
|
||||
|
||||
from flask_appbuilder.models.sqla import Model
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
@@ -43,7 +43,12 @@ class DeleteDatasetCommand(BaseCommand):
|
||||
|
||||
def run(self) -> Model:
|
||||
self.validate()
|
||||
self._model = cast(SqlaTable, self._model)
|
||||
try:
|
||||
# Even though SQLAlchemy should in theory delete rows from the association
|
||||
# table, sporadically Superset will error because the rows are not deleted.
|
||||
# Let's do it manually here to prevent the error.
|
||||
self._model.owners = []
|
||||
dataset = DatasetDAO.delete(self._model, commit=False)
|
||||
db.session.commit()
|
||||
except (SQLAlchemyError, DAODeleteFailedError) as ex:
|
||||
|
||||
Reference in New Issue
Block a user