{"record":{"id":"26cb27974f06e0a3","repo":"hashicorp/nomad","slug":"job-submission-requires-a-namespace","errorCode":null,"errorMessage":"job_submission requires a namespace","messagePattern":"job_submission requires a namespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/state/state_store.go","lineNumber":5797,"sourceCode":"\t\treturn fmt.Errorf(\"UpsertScalingPolicies of policies failed: %v\", err)\n\t}\n\n\treturn nil\n}\n\n// updateJobSubmission stores the original job source and variables associated that the\n// job structure originates from. It is up to the job submitter to include the source\n// material, and as such sub may be nil, in which case nothing is stored.\nfunc (s *StateStore) updateJobSubmission(index uint64, sub *structs.JobSubmission, namespace, jobID string, version uint64, txn *txn) error {\n\t// critical that we operate on a copy; the original must not be modified\n\t// e.g. in the case of job gc and its last second version bump\n\tsub = sub.Copy()\n\n\tswitch {\n\tcase sub == nil:\n\t\treturn nil\n\tcase namespace == \"\":\n\t\treturn errors.New(\"job_submission requires a namespace\")\n\tcase jobID == \"\":\n\t\treturn errors.New(\"job_submission requires a jobID\")\n\tdefault:\n\t\tsub.Namespace = namespace\n\t\tsub.JobID = jobID\n\t\tsub.JobModifyIndex = index\n\t\tsub.Version = version\n\t}\n\n\t// check if we already have a submission for this (namespace, jobID, version)\n\tobj, err := txn.First(\"job_submission\", \"id\", namespace, jobID, version)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif obj != nil {\n\t\t// if we already have a submission for this (namespace, jobID, version)\n\t\t// then there is nothing to do; manually avoid potential for duplicates\n\t\treturn nil","sourceCodeStart":5779,"sourceCodeEnd":5815,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/state/state_store.go#L5779-L5815","documentation":"setJobSubmission (state store helper persisting the JobSubmission object attached to a job) requires an explicit namespace since job submissions are namespaced entities. An empty namespace cannot scope the record, so the write is rejected.","triggerScenarios":"Calling StateStore.JobSubmission setter (via the upsert job path or direct state store use) with namespace=\"\", e.g. a caller forgetting to default the namespace before writing a job that carries a job_submission block.","commonSituations":"Custom tooling or embedded-Nomad code paths that bypass RPC-layer namespace defaulting (normally RPCs default to the \"default\" namespace); passing job structs around without Normalize routines that fill Namespace.","solutions":["Default the namespace to structs.DefaultNamespace (\"default\") before invoking the state store call","Call the job Normalize/Canonicalize routine on the request before writing so Namespace is populated","Include the namespace explicitly in API requests (e.g. ?namespace=... or namespace field in the job JSON)"],"exampleFix":"// before\nstateStore.UpsertJobSubmission(msgType, idx, txn, sub, \"\", jobID, index, version)\n// after\nns := namespace\nif ns == \"\" { ns = structs.DefaultNamespace }\nstateStore.UpsertJobSubmission(msgType, idx, txn, sub, ns, jobID, index, version)","handlingStrategy":"validation","validationCode":"func ensureNamespace(ns string) string {\n    if ns == \"\" { return structs.DefaultNamespace }\n    return ns\n}\n// call: upsertJobSubmission(sub, ensureNamespace(ns), jobID, index, version)","typeGuard":"func hasNamespace(j *structs.Job) bool {\n    return j != nil && j.Namespace != \"\"\n}","tryCatchPattern":"if err := upsert(sub, ns, jobID); err != nil && strings.Contains(err.Error(), \"requires a namespace\") {\n    return upsert(sub, structs.DefaultNamespace, jobID)\n}","preventionTips":["Canonicalize job structs (job.Canonicalize) before state writes","Default namespaces at the RPC boundary, not in state-store helpers","Never pass raw user input namespaces without defaulting empty to \"default\""],"tags":["nomad","state-store","job-submission","validation","namespaces"],"backgroundTag":"missing-required-argument","analyzedSha":"482b49bf1aec006f089bcfc7e632d8f6ac303e5e","analyzedAt":"2026-09-04T07:54:14.808Z","contentChangedAt":"2026-09-04T07:54:14.808Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}