{"record":{"id":"ffd8467e69c57aad","repo":"alibaba/spring-ai-alibaba","slug":"invalid-params-ffd846","errorCode":"INVALID_PARAMS","errorMessage":"provider already exists","messagePattern":"provider already exists","errorType":"error_code","errorClass":"BizException","httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/ProviderManager.java","lineNumber":75,"sourceCode":"\t * Add a new provider\n\t * @param providerConfigInfo Provider configuration information\n\t * @return true if successful\n\t */\n\tpublic boolean addProvider(ProviderConfigInfo providerConfigInfo) {\n\t\tRequestContext context = RequestContextHolder.getRequestContext();\n\t\tString workspaceId = context.getWorkspaceId();\n\t\ttry {\n\t\t\t// 检查提供商是否存在\n\t\t\tQueryWrapper<ProviderEntity> queryWrapper = new QueryWrapper<>();\n\t\t\tqueryWrapper.eq(\"provider\", providerConfigInfo.getProvider());\n\t\t\tif (StringUtils.isNotBlank(context.getWorkspaceId())) {\n\t\t\t\tqueryWrapper.eq(\"workspace_id\", context.getWorkspaceId());\n\t\t\t}\n\t\t\tString provider = providerConfigInfo.getProvider();\n\t\t\tProviderEntity existingProvider = getProviderEntity(provider, workspaceId);\n\t\t\tif (existingProvider != null) {\n\t\t\t\tlog.error(\"provider [{}] already exist\", providerConfigInfo.getProvider());\n\t\t\t\tthrow new BizException(ErrorCode.INVALID_PARAMS.toError(\"input_params\", \"provider already exists\"));\n\t\t\t}\n\n\t\t\tProviderEntity providerEntity = new ProviderEntity();\n\t\t\tproviderEntity.setWorkspaceId(context.getWorkspaceId());\n\t\t\tproviderEntity.setGmtCreate(new Date());\n\t\t\tproviderEntity.setGmtModified(new Date());\n\t\t\tproviderEntity.setIcon(providerConfigInfo.getIcon());\n\t\t\tproviderEntity.setName(providerConfigInfo.getName());\n\t\t\tproviderEntity.setProvider(providerConfigInfo.getProvider());\n\t\t\tproviderEntity.setDescription(providerConfigInfo.getDescription());\n\t\t\tproviderEntity.setSource(StringUtils.isNotBlank(providerConfigInfo.getSource())\n\t\t\t\t\t? providerConfigInfo.getSource() : DataSourceEnum.custom.name());\n\t\t\tproviderEntity.setEnable(providerConfigInfo.getEnable() != null ? providerConfigInfo.getEnable() : true);\n\t\t\tproviderEntity.setCredential(providerConfigInfo.getCredential() == null ? \"{}\"\n\t\t\t\t\t: JsonUtils.toJson(providerConfigInfo.getCredential()));\n\t\t\tproviderEntity.setSupportedModelTypes(\n\t\t\t\t\tproviderConfigInfo.getSupportedModelTypes().stream().collect(Collectors.joining(\",\")));\n\t\t\tproviderEntity.setCreator(context.getAccountId());","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-core/src/main/java/com/alibaba/cloud/ai/studio/core/base/manager/ProviderManager.java#L57-L93","documentation":"ProviderManager.addProvider throws BizException(INVALID_PARAMS, 'provider already exists') when a provider with the same name already exists in the target workspace — getProviderEntity(provider, workspaceId) returns a non-null row. It enforces per-workspace uniqueness of provider names and is thrown before any insert happens.","triggerScenarios":"Calling addProvider with a providerConfigInfo whose provider name matches an existing row in the same workspace (case-exact match on the provider column).","commonSituations":"Double-submitting a creation form; retrying a request that actually succeeded the first time; seeding scripts run twice; trying to register a built-in provider name that already exists in the workspace.","solutions":["Check for the provider's existence first (query providers in the workspace) and update instead of insert if present","Use a different provider name if a distinct provider is intended","Make creation idempotent: catch this BizException and treat it as success when re-registering the same config","Deduplicate seed/init scripts so they run only once"],"exampleFix":"// before\nproviderManager.addProvider(config);\n// after\ntry {\n    providerManager.addProvider(config);\n} catch (BizException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"provider already exists\")) {\n        log.info(\"Provider {} already registered, skipping\", config.getProvider());\n    } else {\n        throw e;\n    }\n}","handlingStrategy":"try-catch","validationCode":"boolean providerExists = providerManager.getProviders(workspaceId).stream()\n    .anyMatch(p -> p.getProvider().equals(config.getProvider()));\nif (providerExists) { /* update instead of create */ }","typeGuard":"boolean providerExistsInWorkspace(String provider, String workspaceId) {\n    return provider != null\n        && providerManager.getProviders(workspaceId).stream()\n            .anyMatch(p -> p.getProvider().equals(provider));\n}","tryCatchPattern":"try {\n    providerManager.addProvider(config);\n} catch (BizException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"provider already exists\")) {\n        providerManager.updateProvider(config); // idempotent upsert\n    } else {\n        throw e;\n    }\n}","preventionTips":["Implement upsert semantics: check-then-update instead of blind insert","Guard seed/init scripts against double execution","Disable double-submit on creation UIs","Document that provider names are unique per workspace"],"tags":["duplicate","provider","uniqueness","database"],"backgroundTag":"file-already-exists","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}