{"record":{"id":"7d41874bf4fba3a1","repo":"apache/superset","slug":"there-are-associated-alerts-or-reports-report-n-7d4187","errorCode":null,"errorMessage":"There are associated alerts or reports: %(report_names)s","messagePattern":"There are associated alerts or reports: (.+?)","errorType":"exception","errorClass":"DatabaseDeleteFailedReportsExistError","httpStatus":500,"severity":"error","filePath":"superset/commands/database/delete.py","lineNumber":59,"sourceCode":"        self._model_id = model_id\n        self._model: Optional[Database] = None\n\n    @transaction(on_error=partial(on_error, reraise=DatabaseDeleteFailedError))\n    def run(self) -> None:\n        self.validate()\n        assert self._model\n        DatabaseDAO.delete([self._model])\n\n    def validate(self) -> None:\n        # Validate/populate model exists\n        self._model = DatabaseDAO.find_by_id(self._model_id)\n        if not self._model:\n            raise DatabaseNotFoundError()\n        # Check there are no associated ReportSchedules\n\n        if reports := ReportScheduleDAO.find_by_database_id(self._model_id):\n            report_names = [report.name for report in reports]\n            raise DatabaseDeleteFailedReportsExistError(\n                _(\n                    \"There are associated alerts or reports: %(report_names)s\",\n                    report_names=\",\".join(report_names),\n                )\n            )\n        # Check if there are datasets for this database. ``self._model.tables``\n        # would now hide soft-deleted datasets (``SqlaTable`` inherits\n        # ``SoftDeleteMixin``, so the relationship lazy-load applies the\n        # visibility filter), letting a database whose datasets are all\n        # soft-deleted look empty and be hard-deleted while ``tables.database_id``\n        # rows still reference it. Count with the visibility filter bypassed so\n        # soft-deleted datasets still block the delete.\n        from superset.connectors.sqla.models import (  # pylint: disable=import-outside-toplevel\n            SqlaTable,\n        )\n        from superset.extensions import (  # pylint: disable=import-outside-toplevel\n            db,\n        )","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/apache/superset/blob/f4587218dd19d046c3e4d00063e7d27f8a2ed354/superset/commands/database/delete.py#L41-L77","documentation":"DatabaseDeleteFailedReportsExistError raised in DeleteDatabaseCommand.validate (delete.py:59) when ReportScheduleDAO.find_by_database_id(self._model_id) returns rows. Superset refuses to hard-delete a database that alert/report schedules depend on; the message interpolates the offending schedule names via the _() gettext template 'There are associated alerts or reports: %(report_names)s'.","triggerScenarios":"DELETE /api/v1/database/<id> when at least one Alert or Report schedule targets a chart/dataset backed by this database.","commonSituations":"Legacy weekly report emails pointing at a database being decommissioned; alerts on datasets nobody remembered; deleting a database after migrating its datasets but not the schedules.","solutions":["The error message names the schedules — delete or re-point each one (DELETE /api/v1/report/<id> or change its target).","Search all reports for dependencies before deleting a database: GET /api/v1/report/ and inspect targets.","If the reports are obsolete, pause/delete them in bulk via the UI (Manage > Alerts & Reports).","Retry the database delete once no schedule references it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"from superset.daos.report import ReportScheduleDAO\n\ndef database_has_reports(model_id: int) -> bool:\n    return ReportScheduleDAO.find_by_database_id(model_id) is not None","typeGuard":null,"tryCatchPattern":"from superset.commands.database.exceptions import DatabaseDeleteFailedReportsExistError\n\ntry:\n    DeleteDatabaseCommand(model_id).run()\nexcept DatabaseDeleteFailedReportsExistError as ex:\n    # ex.message lists the schedule names: delete or re-point them, then retry\n    show_list(ex.message)","preventionTips":["Sweep alerts/reports for a database before decommissioning it.","When migrating a database, re-point report schedules to the new database in the same change.","The error message enumerates the offending schedule names — use it as a worklist."],"tags":["database","delete","alerts","reports","dependency"],"backgroundTag":null,"analyzedSha":"f4587218dd19d046c3e4d00063e7d27f8a2ed354","analyzedAt":"2026-08-14T22:39:27.425Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}