{"record":{"id":"0c277dcff4943117","repo":"kubesphere/kubesphere","slug":"the-name-of-the-object-s-does-not-match-the-nam-0c277d","errorCode":null,"errorMessage":"the name of the object (%s) does not match the name on the URL (%s)","messagePattern":"the name of the object \\((.+?)\\) does not match the name on the URL \\((.+?)\\)","errorType":"http","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/kapis/tenant/v1beta1/handler.go","lineNumber":139,"sourceCode":"\t}\n\n\t_ = response.WriteEntity(servererr.None)\n}\n\nfunc (h *handler) UpdateWorkspaceTemplate(req *restful.Request, resp *restful.Response) {\n\tworkspaceName := req.PathParameter(\"workspace\")\n\tvar workspace tenantv1beta1.WorkspaceTemplate\n\n\terr := req.ReadEntity(&workspace)\n\n\tif err != nil {\n\t\tklog.Error(err)\n\t\tapi.HandleBadRequest(resp, req, err)\n\t\treturn\n\t}\n\n\tif workspaceName != workspace.Name {\n\t\terr := fmt.Errorf(\"the name of the object (%s) does not match the name on the URL (%s)\", workspace.Name, workspaceName)\n\t\tklog.Errorf(\"%+v\", err)\n\t\tapi.HandleBadRequest(resp, req, err)\n\t\treturn\n\t}\n\n\trequestUser, ok := request.UserFrom(req.Request.Context())\n\tif !ok {\n\t\terr := fmt.Errorf(\"cannot obtain user info\")\n\t\tklog.Errorln(err)\n\t\tapi.HandleForbidden(resp, req, err)\n\t}\n\n\tupdated, err := h.tenant.UpdateWorkspaceTemplate(requestUser, &workspace)\n\n\tif err != nil {\n\t\tklog.Error(err)\n\t\tif errors.IsNotFound(err) {\n\t\t\tapi.HandleNotFound(resp, req, err)","sourceCodeStart":121,"sourceCodeEnd":157,"githubUrl":"https://github.com/kubesphere/kubesphere/blob/04a29b5c601470fa6bc2f2e92358dcb802a0d414/pkg/kapis/tenant/v1beta1/handler.go#L121-L157","documentation":"UpdateWorkspaceTemplate validates that the name in the submitted workspace object body matches the workspaceName path parameter. Kubernetes semantics require these to be equal; a mismatch means the client is trying to update a different object than the URL addresses, so the handler returns 400 with 'the name of the object (%s) does not match the name on the URL (%s)'.","triggerScenarios":"PUT /kapis/tenant.kubesphere.io/v1beta1/workspaces/{workspace} where the JSON body's metadata.name differs from {workspace} (e.g. body fetched from another workspace, or name edited in a UI form).","commonSituations":"Copying a workspace spec and forgetting to change metadata.name; GET from workspace-A then PUT against workspace-B; renaming attempts (renames are not allowed via PUT); templating bugs where the URL uses a variable but the body is hardcoded.","solutions":["Ensure body metadata.name exactly equals the URL workspace segment before issuing the PUT","Refetch the object from the same workspace you intend to update","To rename a workspace, create a new one and migrate instead of changing metadata.name","Fix template/tooling that interpolates the URL path but not the body name"],"exampleFix":"// before\nbody := {\"metadata\":{\"name\":\"workspace-a\"}} // URL: /workspaces/workspace-b\n// after\nbody := {\"metadata\":{\"name\":\"workspace-b\"}} // matches URL /workspaces/workspace-b","handlingStrategy":"validation","validationCode":"func checkWorkspaceUpdate(urlName string, obj metav1.Object) error {\n\tif obj.GetName() != urlName {\n\t\treturn fmt.Errorf(\"body name %q != URL name %q\", obj.GetName(), urlName)\n\t}\n\treturn nil\n}\n// call before issuing PUT","typeGuard":null,"tryCatchPattern":"if err := checkWorkspaceUpdate(wsName, workspace); err != nil { return err }\n// server already returns 400 on mismatch; treat 400 with 'does not match the name on the URL' as a client bug, not retryable\nif resp.StatusCode == 400 && strings.Contains(body, \"does not match the name on the URL\") {\n\treturn fmt.Errorf(\"fix client payload: %s\", body)\n}","preventionTips":["Always derive the PUT body from a GET on the same resource path","Never edit metadata.name on objects destined for update","Add client-side name-consistency assertions in SDK/tooling","Watch for copy-paste between workspaces"],"tags":["validation","kubernetes","kubesphere","rest-api"],"backgroundTag":"resource-name-mismatch","analyzedSha":"04a29b5c601470fa6bc2f2e92358dcb802a0d414","analyzedAt":"2026-09-03T18:33:15.017Z","contentChangedAt":"2026-09-03T18:33:15.017Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}