{"record":{"id":"a075df628d4de6ec","repo":"paascloud/paascloud-master","slug":"opc10040007","errorCode":"OPC10040007","errorMessage":"OPC10040007","messagePattern":"OPC10040007","errorType":"error_code","errorClass":"OpcBizException","httpStatus":null,"severity":"error","filePath":"paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptAttachmentServiceImpl.java","lineNumber":149,"sourceCode":"\t@Override\n\tpublic int deleteFile(final Long attachmentId) throws QiniuException {\n\t\tOptAttachment optAttachment = optAttachmentMapper.selectByPrimaryKey(attachmentId);\n\t\tif (optAttachment != null) {\n\t\t\toptOssService.deleteFile(optAttachment.getPath() + optAttachment.getName(), optAttachment.getBucketName());\n\t\t\treturn optAttachmentMapper.deleteByPrimaryKey(attachmentId);\n\t\t}\n\t\treturn 1;\n\t}\n\n\t@Override\n\tpublic void saveAttachment(OptAttachment optAttachment, LoginAuthDto loginAuthDto) {\n\t\toptAttachment.setUpdateInfo(loginAuthDto);\n\t\tif (optAttachment.isNew()) {\n\t\t\toptAttachmentMapper.insertSelective(optAttachment);\n\t\t} else {\n\t\t\tint result = optAttachmentMapper.updateByPrimaryKeySelective(optAttachment);\n\t\t\tif (result < 1) {\n\t\t\t\tthrow new OpcBizException(ErrorCodeEnum.OPC10040007, optAttachment.getId());\n\t\t\t}\n\t\t}\n\t}\n\n\t@Override\n\tpublic OptUploadFileRespDto rpcUploadFile(OptUploadFileReqDto optUploadFileReqDto) throws IOException {\n\t\tString fileType = optUploadFileReqDto.getFileType();\n\t\tString filePath = optUploadFileReqDto.getFilePath();\n\t\tString bucketName = optUploadFileReqDto.getBucketName();\n\t\tOptUploadFileByteInfoReqDto uploadFileByteInfoReqDto = optUploadFileReqDto.getUploadFileByteInfoReqDto();\n\t\tLoginAuthDto authResDto = new LoginAuthDto();\n\t\tauthResDto.setUserId(optUploadFileReqDto.getUserId());\n\t\tauthResDto.setUserName(optUploadFileReqDto.getUserName());\n\n\t\tif (PublicUtil.isEmpty(filePath)) {\n\t\t\tfilePath = GlobalConstant.Oss.DEFAULT_FILE_PATH;\n\t\t}\n\t\tInputStream is = null;","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/paascloud/paascloud-master/blob/781281a9503332ed3cef44ea618349d14230a127/paascloud-provider/paascloud-provider-opc/src/main/java/com/paascloud/provider/service/impl/OptAttachmentServiceImpl.java#L131-L167","documentation":"OpcBizException with code OPC10040007 thrown by OptAttachmentServiceImpl.saveAttachment when updating an existing attachment (isNew() false) affects zero rows in optAttachmentMapper.updateByPrimaryKeySelective. This means the record with the given id no longer exists (or was concurrently deleted), so the update is a no-op and is treated as a business failure.","triggerScenarios":"saveAttachment called with an attachment whose id points to a deleted/nonexistent row; concurrent transaction deleted the attachment between load and update; caller passed a stale id from the client; wrong datasource/env so the id does not exist.","commonSituations":"Double-submit forms where one request deleted the attachment; optimistic-concurrency races in multi-instance deployments; frontend caching an id after the record was removed; environment mismatch (test id used against prod DB).","solutions":["Verify the attachment id exists before updating (query by primary key)","Use insert-on-missing/upsert semantics or re-create the record if it should exist","Add optimistic locking/version check and surface a clear 'record changed or deleted' message to the user","Confirm the client is not sending stale ids after deletion"],"exampleFix":"// before\nint result = optAttachmentMapper.updateByPrimaryKeySelective(optAttachment);\nif (result < 1) {\n    throw new OpcBizException(ErrorCodeEnum.OPC10040007, optAttachment.getId());\n}\n// after\nOptAttachment existing = optAttachmentMapper.selectByPrimaryKey(optAttachment.getId());\nif (existing == null) {\n    optAttachmentMapper.insertSelective(optAttachment); // or fail fast with a clearer message\n} else {\n    optAttachmentMapper.updateByPrimaryKeySelective(optAttachment);\n}","handlingStrategy":"validation","validationCode":"OptAttachment existing = optAttachmentMapper.selectByPrimaryKey(optAttachment.getId());\nif (existing == null) {\n    throw new OpcBizException(ErrorCodeEnum.OPC10040007, optAttachment.getId()); // or insert\n}","typeGuard":"if (optAttachment == null || optAttachment.getId() == null) { throw new IllegalArgumentException(\"id required for update\"); }","tryCatchPattern":"try { attachmentService.saveAttachment(optAttachment, loginAuthDto); } catch (OpcBizException e) { if (\"OPC10040007\".equals(e.getCode())) { /* record vanished; reload or recreate */ } }","preventionTips":["Reload the record by id before updating","Use optimistic locking to detect concurrent deletes","Invalidate client caches after deletions so stale ids are not re-submitted","Verify environment/datasource consistency"],"tags":["attachment","update-failed","stale-record"],"backgroundTag":"database-write-failed","analyzedSha":"781281a9503332ed3cef44ea618349d14230a127","analyzedAt":"2026-09-10T10:59:02.070Z","contentChangedAt":"2026-09-10T10:59:02.070Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}