{"record":{"id":"87f683b82773ffef","repo":"iflytek/astron-agent","slug":"database-delete-failed-cited","errorCode":"DATABASE_DELETE_FAILED_CITED","errorMessage":"DATABASE_DELETE_FAILED_CITED","messagePattern":"DATABASE_DELETE_FAILED_CITED","errorType":"error_code","errorClass":"BusinessException","httpStatus":null,"severity":"warning","filePath":"console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java","lineNumber":175,"sourceCode":"                }\n                dbInfo.setDescription(databaseDto.getDescription());\n            }\n            dbInfoMapper.updateById(dbInfo);\n        } catch (Exception ex) {\n            log.error(\"Failed to update database, params={}\", JSONObject.toJSONString(databaseDto), ex);\n            throw new BusinessException(ResponseEnum.DATABASE_UPDATE_FAILED);\n        }\n    }\n\n    public void delete(Long id) {\n        try {\n            // Check if the database is being referenced\n            dataPermissionCheckTool.checkDbUpdateBelong(id);\n            DbInfo dbInfo = dbInfoMapper.selectById(id);\n            Long count = flowDbRelMapper.selectCount(new QueryWrapper<FlowDbRel>().lambda()\n                    .eq(FlowDbRel::getDbId, dbInfo.getDbId()));\n            if (count > 0) {\n                throw new BusinessException(ResponseEnum.DATABASE_DELETE_FAILED_CITED);\n            }\n            // Delete from core system\n            coreSystemService.dropDataBase(dbInfo.getDbId(), UserInfoManagerHandler.getUserId());\n            dbInfo.setDeleted(true);\n            dbInfoMapper.updateById(dbInfo);\n        } catch (Exception ex) {\n            log.error(\"Failed to delete database, dbId={}\", id, ex);\n            throw ex;\n        }\n    }\n\n    @Transactional\n    public void copyDatabase(Long id) {\n        try {\n            DbInfo dbInfo = dbInfoMapper.selectById(id);\n            DbInfo newDbInfo = new DbInfo();\n            newDbInfo.setName(dbInfo.getName() + \"_副本\");\n            newDbInfo.setDescription(dbInfo.getDescription());","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/iflytek/astron-agent/blob/5e758547a83371a5a4b29dadf4ac03e8dd527635/console/backend/toolkit/src/main/java/com/iflytek/astron/console/toolkit/service/database/DatabaseService.java#L157-L193","documentation":"Thrown by DatabaseService.delete when the database is still referenced by one or more workflow relations: flowDbRelMapper.selectCount on dbId returns > 0. Deletion is blocked to avoid breaking flows that depend on the database. Note this BusinessException is again caught by the same method's outer catch and re-wrapped (see that method's generic failure error).","triggerScenarios":"Calling delete(id) while at least one row in flow_db_rel references dbInfo.getDbId().","commonSituations":"Trying to remove a database that is wired into an active workflow; leftover flow_db_rel rows from deleted flows that were not cleaned up; shared dev databases still bound to test flows.","solutions":["Unbind/remove the workflows referencing this database, then retry delete","Query flow_db_rel by dbId to find which flows block deletion","If relations are stale (flows already deleted), clean up orphan flow_db_rel rows","Choose a different database for new flows and retire this one gradually"],"exampleFix":"// before\ndatabaseService.delete(dbId); // throws if cited by flows\n// after\nlong refs = flowDbRelMapper.selectCount(new QueryWrapper<FlowDbRel>().eq(FlowDbRel::getDbId, dbId));\nif (refs == 0) { databaseService.delete(dbId); }","handlingStrategy":"validation","validationCode":"long refs = flowDbRelMapper.selectCount(new QueryWrapper<FlowDbRel>().lambda().eq(FlowDbRel::getDbId, dbId));\nif (refs > 0) { /* block delete or unbind flows first */ }","typeGuard":null,"tryCatchPattern":"try { databaseService.delete(id); } catch (BusinessException e) { if (\"DATABASE_DELETE_FAILED_CITED\".equals(e.getCode())) { /* list dependent flows and ask user to unbind */ } else { throw e; } }","preventionTips":["Check flow_db_rel references before offering delete in the UI","Clean up flow_db_rel rows when flows are deleted","Communicate dependencies to users before hard deletes"],"tags":["referential-integrity","database","dependency","java"],"backgroundTag":"resource-in-use","analyzedSha":"5e758547a83371a5a4b29dadf4ac03e8dd527635","analyzedAt":"2026-09-12T08:03:51.356Z","contentChangedAt":"2026-09-12T08:03:51.356Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}