{"record":{"id":"d09932bdbc2b7a4e","repo":"apache/shenyu","slug":"scale-rule-is-not-existed","errorCode":null,"errorMessage":"scale rule is not existed","messagePattern":"scale rule is not existed","errorType":"validation","errorClass":"ShenyuAdminException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScaleRlueController.java","lineNumber":130,"sourceCode":"     *\n     * @param scaleRuleDTO scaleRuleDTO\n     * @return ShenyuAdminResult\n     */\n    @PostMapping\n    public ShenyuAdminResult createRule(@Valid @RequestBody final ScaleRuleDTO scaleRuleDTO) {\n        return ShenyuAdminResult.success(ShenyuResultMessage.CREATE_SUCCESS, scaleRuleService.createOrUpdate(scaleRuleDTO));\n    }\n\n    /**\n     * update rule.\n     *\n     * @param scaleRuleDTO scaleRuleDTO\n     * @return ShenyuAdminResult\n     */\n    @PutMapping\n    public ShenyuAdminResult updateRule(@Valid @RequestBody final ScaleRuleDTO scaleRuleDTO) {\n        if (!scaleRuleMapper.existed(scaleRuleDTO.getId())) {\n            throw new ShenyuAdminException(\"scale rule is not existed\");\n        }\n        return ShenyuAdminResult.success(ShenyuResultMessage.UPDATE_SUCCESS, scaleRuleService.createOrUpdate(scaleRuleDTO));\n    }\n\n    /**\n     * delete rules.\n     *\n     * @param ids ids\n     * @return ShenyuAdminResult\n     */\n    @DeleteMapping(\"/batch\")\n    public ShenyuAdminResult deleteRules(@RequestBody @NotEmpty final List<@NotBlank String> ids) {\n        return ShenyuAdminResult.success(ShenyuResultMessage.DELETE_SUCCESS, scaleRuleService.delete(ids));\n    }\n}\n","sourceCodeStart":112,"sourceCodeEnd":146,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ScaleRlueController.java#L112-L146","documentation":"PUT /scale/rule (ScaleRlueController.updateRule) checks scaleRuleMapper.existed(id) before updating; when no scale rule row exists for the DTO's id it throws ShenyuAdminException(\"scale rule is not existed\"). Updates are id-based and never create-or-upsert.","triggerScenarios":"PUT /scale/rule with a ScaleRuleDTO whose id does not exist in the scale_rule table (stale id, id from another environment, or calling update instead of create for a new rule).","commonSituations":"Dashboard stale tab holding a rule deleted elsewhere; automation scripts reusing hardcoded ids; confusing create (POST) with update (PUT) semantics.","solutions":["Confirm the rule id exists (GET the rule list / check the scale_rule table) and send the correct id","If the rule is new, use POST (createRule) instead of PUT","Refresh the dashboard page to clear stale ids and retry"],"exampleFix":"// before\nPUT /scale/rule  {\"id\":\"nonexistent-id\", ...}\n// after\nPOST /scale/rule {\"name\":\"my-rule\", ...}   // create first, then PUT with returned id","handlingStrategy":"validation","validationCode":"ScaleRuleDTO existing = scaleRuleApi.getById(dto.getId());\nif (existing == null) {\n    scaleRuleApi.createRule(dto);      // create instead of update\n} else {\n    scaleRuleApi.updateRule(dto);\n}","typeGuard":null,"tryCatchPattern":"try {\n    scaleRuleApi.updateRule(dto);\n} catch (ShenyuAdminException e) {\n    if (\"scale rule is not existed\".equals(e.getMessage())) { scaleRuleApi.createRule(dto); }\n}","preventionTips":["Fetch the current rule list before updating and use ids from that response","Never hardcode scale rule ids in scripts","Refresh dashboards to avoid stale ids from deleted rules"],"tags":["rest-api","scale-rule","record-not-found"],"backgroundTag":"entity-not-found","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-19T12:17:13.211Z"}