{"record":{"id":"dda163f74746881d","repo":"weaviate/weaviate","slug":"a-target-namespace-is-required-on-namespace-enable","errorCode":null,"errorMessage":"a target namespace is required on namespace-enabled clusters","messagePattern":"a target namespace is required on namespace-enabled clusters","errorType":"http","errorClass":null,"httpStatus":422,"severity":"error","filePath":"adapters/handlers/rest/db_users/handlers_db_users.go","lineNumber":767,"sourceCode":"\t\tif err := h.authorizer.Authorize(ctx, principal, authorization.CREATE, authorization.Users(wildcardKey)...); err != nil {\n\t\t\treturn experimental.NewImportUsersForbidden().WithPayload(cerrors.ErrPayloadFromSingleErr(principal, err))\n\t\t}\n\t} else {\n\t\tkeys := make([]string, 0, len(params.Body.Users))\n\t\tfor _, rec := range params.Body.Users {\n\t\t\tkeys = append(keys, apikey.MakeUserKey(bareUserID(rec), targetNamespace))\n\t\t}\n\t\tif err := h.authorizer.Authorize(ctx, principal, authorization.CREATE, authorization.Users(keys...)...); err != nil {\n\t\t\treturn experimental.NewImportUsersForbidden().WithPayload(cerrors.ErrPayloadFromSingleErr(principal, err))\n\t\t}\n\t\tif err := h.authorizer.Authorize(ctx, principal, authorization.UPDATE, authorization.Users(keys...)...); err != nil {\n\t\t\treturn experimental.NewImportUsersForbidden().WithPayload(cerrors.ErrPayloadFromSingleErr(principal, err))\n\t\t}\n\t}\n\n\tif h.namespacesEnabled {\n\t\tif targetNamespace == \"\" {\n\t\t\treturn experimental.NewImportUsersUnprocessableEntity().WithPayload(cerrors.ErrPayloadFromSingleErr(principal, errors.New(\"a target namespace is required on namespace-enabled clusters\")))\n\t\t}\n\t} else if targetNamespace != \"\" {\n\t\treturn experimental.NewImportUsersUnprocessableEntity().WithPayload(cerrors.ErrPayloadFromSingleErr(principal, errors.New(\"namespaces are not enabled on this cluster; cannot import into a namespace\")))\n\t}\n\n\tif len(params.Body.Users) == 0 {\n\t\treturn experimental.NewImportUsersOK().WithPayload(&models.UserImportResponse{Results: []*models.UserImportResult{}})\n\t}\n\n\t// The apply re-checks the namespace; this only saves a round-trip per user\n\t// when this node already knows it is inactive.\n\tif err := namespaces.RequireActive(h.namespaces, targetNamespace); err != nil {\n\t\treturn renderImportUsersNamespaceErr(principal, err)\n\t}\n\n\tresponse := &models.UserImportResponse{Results: make([]*models.UserImportResult, 0, len(params.Body.Users))}\n\tfor _, rec := range params.Body.Users {\n\t\tresponse.Results = append(response.Results, h.importOneUser(ctx, targetNamespace, rec))","sourceCodeStart":749,"sourceCodeEnd":785,"githubUrl":"https://github.com/weaviate/weaviate/blob/75aa4b6d11f8818305aafd4440b4e32794f7ca04/adapters/handlers/rest/db_users/handlers_db_users.go#L749-L785","documentation":"On clusters with the namespaces (multi-namespace db users) feature enabled, every imported user must be assigned a target namespace. importUsers returns 422 when the namespace-enabled cluster receives an import request whose body has no namespace field.","triggerScenarios":"POST /v1/users/db/import with a valid body whose namespace is empty/omitted while h.namespacesEnabled is true (AUTHENTICATION_DB_USERS_NAMESPACES_ENABLED).","commonSituations":"Export files produced on a namespace-less cluster imported into a namespace-enabled cluster; clients written before namespaces existed; templates omitting the new namespace field after a version upgrade.","solutions":["Add a non-empty namespace to the import body: {\"namespace\": \"<target>\", \"users\": [...]}","List existing namespaces first and pick a valid one","If namespaces are not needed, disable AUTHENTICATION_DB_USERS_NAMESPACES_ENABLED so legacy imports are accepted","Update the migration tooling to require a namespace when the target cluster is namespace-enabled"],"exampleFix":"// before\n{\"users\":[{\"username\":\"alice\",\"credentials\":\"...\"}]}\n// after\n{\"namespace\":\"team-a\",\"users\":[{\"username\":\"alice\",\"credentials\":\"...\"}]}","handlingStrategy":"validation","validationCode":"if namespacesEnabled && (importReq.Namespace == \"\") {\n  return errors.New(\"a target namespace is required on namespace-enabled clusters\")\n}","typeGuard":"func importBodyValid(b *UserImportRequest, namespacesEnabled bool) bool {\n  return b != nil && (!namespacesEnabled || b.Namespace != \"\")\n}","tryCatchPattern":"if resp.StatusCode == 422 && strings.Contains(body, \"target namespace is required\") {\n  return fmt.Errorf(\"add \\\"namespace\\\": \\\"<target>\\\" to the import body\")\n}","preventionTips":["Check whether the target cluster has namespaces enabled before building the import body","Fetch the namespace list first and default to an existing valid namespace","Update legacy import scripts after enabling namespaces","Validate the body shape with a schema check before sending"],"tags":["rest-api","db-users","namespaces","validation"],"backgroundTag":"missing-required-argument","analyzedSha":"75aa4b6d11f8818305aafd4440b4e32794f7ca04","analyzedAt":"2026-09-04T14:58:20.392Z","contentChangedAt":"2026-09-04T14:58:20.392Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}