{"record":{"id":"61c4debfe5e4d67b","repo":"apache/pulsar","slug":"s-s-already-exists","errorCode":null,"errorMessage":"%s %s already exists","messagePattern":"(.+?) (.+?) already exists","errorType":"http","errorClass":"RestException","httpStatus":400,"severity":"error","filePath":"pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java","lineNumber":147,"sourceCode":"        } catch (PulsarAdminException.NotFoundException e) {\n            log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", functionName)\n\n                    .attr(\"tenant3\", tenant).log(\"/ / Tenant does not exist\");\n            throw new RestException(Response.Status.BAD_REQUEST, \"Tenant does not exist\");\n        } catch (PulsarAdminException e) {\n            log.error().attr(\"tenant\", tenant).attr(\"namespace\", namespace).attr(\"componentName\", functionName)\n\n                    .exception(e).log(\"/ / Issues getting tenant data\");\n            throw new RestException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());\n        }\n\n        FunctionMetaDataManager functionMetaDataManager = worker().getFunctionMetaDataManager();\n\n        if (functionMetaDataManager.containsFunction(tenant, namespace, functionName)) {\n            log.error().attr(\"componentType\", ComponentTypeUtils.toString(componentType)).attr(\"tenant\", tenant)\n\n                    .attr(\"namespace\", namespace).attr(\"componentName\", functionName).log(\"/ / already exists\");\n            throw new RestException(Response.Status.BAD_REQUEST, String.format(\"%s %s already exists\",\n                    ComponentTypeUtils.toString(componentType), functionName));\n        }\n\n        FunctionDetails functionDetails;\n        File componentPackageFile = null;\n        try {\n\n            // validate parameters\n            try {\n                if (isNotBlank(functionPkgUrl)) {\n                    componentPackageFile = getPackageFile(componentType, functionPkgUrl);\n                    functionDetails = validateUpdateRequestParams(tenant, namespace, functionName,\n                            functionConfig, componentPackageFile);\n                } else {\n                    if (uploadedInputStream != null) {\n                        componentPackageFile = WorkerUtils.dumpToTmpFile(uploadedInputStream);\n                    }\n                    functionDetails = validateUpdateRequestParams(tenant, namespace, functionName,","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/apache/pulsar/blob/820761864ed8e2a7d2e52dd9763ad2ae117c1395/pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java#L129-L165","documentation":"registerFunction checks the worker's FunctionMetaDataManager for an existing function with the same tenant/namespace/name and rejects duplicate registration with HTTP 400 '<ComponentType> <name> already exists' (e.g. 'Function exclamation already exists'). Function names are unique keys within a tenant/namespace.","triggerScenarios":"POSTing a registration for a function name that already exists in that tenant/namespace — re-running a provisioning script, or conflicting with an existing function/sink/source entry with the same name.","commonSituations":"CI/CD job replaying a create call instead of update; tenant/namespace reused where the name is already taken; confusion between create (registerFunction) and update (updateFunction) endpoints.","solutions":["Use the update API ('pulsar-admin functions update' or admin.functions().updateFunction) for existing components","Delete the existing function first ('pulsar-admin functions delete') if replacement via create is intended","Choose a unique functionName, or list existing functions ('pulsar-admin functions list') to check availability before creating"],"exampleFix":"// before\nadmin.functions().createFunction(tenant, ns, name, pkgUrl, cfg, null); // exists\n// after\nadmin.functions().updateFunction(tenant, ns, name, pkgUrl, cfg, null);","handlingStrategy":"try-catch","validationCode":"boolean exists = admin.functions().getFunctions(tenant, namespace).contains(functionName);\nif (exists) { admin.functions().updateFunction(tenant, namespace, functionName, pkgUrl, cfg, null); }\nelse { admin.functions().createFunction(tenant, namespace, functionName, pkgUrl, cfg, null); }","typeGuard":null,"tryCatchPattern":"try { admin.functions().createFunction(...); }\ncatch (PulsarAdminException e) {\n    if (e.getStatusCode() == 400 && String.valueOf(e.getMessage()).contains(\"already exists\")) {\n        admin.functions().updateFunction(tenant, namespace, functionName, pkgUrl, cfg, null);\n    }\n}","preventionTips":["Prefer idempotent create-or-update logic in CI/CD","Check 'pulsar-admin functions list' before create","Use unique per-env function names to avoid collisions"],"tags":["pulsar-functions","duplicate","rest-api"],"backgroundTag":"resource-already-exists","analyzedSha":"820761864ed8e2a7d2e52dd9763ad2ae117c1395","analyzedAt":"2026-09-06T00:14:20.138Z","contentChangedAt":"2026-09-06T00:14:20.138Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}