{"record":{"id":"3d47d51855e829a2","repo":"hashicorp/nomad","slug":"no-attribute-provided-but-is-required-by-operator","errorCode":null,"errorMessage":"no attribute provided but is required by operator","messagePattern":"no attribute provided but is required by operator","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":10110,"sourceCode":"\t\t\t}\n\t\t}\n\tcase ConstraintAttributeIsSet, ConstraintAttributeIsNotSet:\n\t\tif c.RTarget != \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Operator %q does not support an RTarget\", c.Operand))\n\t\t}\n\tcase \"=\", \"==\", \"is\", \"!=\", \"not\", \"<\", \"<=\", \">\", \">=\":\n\t\tif c.RTarget == \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Operator %q requires an RTarget\", c.Operand))\n\t\t}\n\tdefault:\n\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Unknown constraint type %q\", c.Operand))\n\t}\n\n\t// If the constraint must have a \"LTarget\" (attribute in the job spec), then\n\t// ensure it is not an empty string and is valid.\n\tif requireLtarget {\n\t\tif c.LTarget == \"\" {\n\t\t\tmErr.Errors = append(mErr.Errors, errors.New(\"no attribute provided but is required by operator\"))\n\t\t} else {\n\t\t\tif err := validateConstraintAttribute(c.LTarget); err != nil {\n\t\t\t\tmErr.Errors = append(mErr.Errors, err)\n\t\t\t}\n\t\t}\n\n\t}\n\n\treturn mErr.ErrorOrNil()\n}\n\n// DiffID fulfills the DiffableWithID interface.\nfunc (c *Constraint) DiffID() string {\n\treturn c.String()\n}\n\ntype Constraints []*Constraint\n","sourceCodeStart":10092,"sourceCodeEnd":10128,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L10092-L10128","documentation":"Constraint.Validate() requires an LTarget (the attribute/expression being compared) for all operands that need one (most operators except distinct_hosts, distinct_property with no target, etc.). When Operand demands an LTarget but c.LTarget is the empty string, this error is appended to the validation multierror.","triggerScenarios":"Submitting a constraint with an operator but no attribute, e.g. `constraint { operator = \"regexp\"; value = \"web-.*\" }` without attribute, or Constraint{Operand: \"=\", RTarget: \"x\"} in Go.","commonSituations":"Copy-pasting constraint examples and dropping the attribute line; writing distinct_hosts-style constraints then switching the operator to something that needs a target; programmatic generation where LTarget is filled conditionally and the condition failed.","solutions":["Add the required attribute/LTarget to the constraint, e.g. attribute = \"${node.class}\".","If you intended a node-wide constraint like distinct_hosts, use operator \"distinct_hosts\" with no attribute, or set the proper attribute.","Verify the attribute expression syntax (must be like ${node.attr} or a literal) so validateConstraintAttribute doesn't add further errors.","Run `nomad job validate` before submitting."],"exampleFix":"// before\nconstraint {\n  operator = \"regexp\"\n  value    = \"r[1-2]\"\n}\n// after\nconstraint {\n  attribute = \"${meta.rack}\"\n  operator  = \"regexp\"\n  value     = \"r[1-2]\"\n}","handlingStrategy":"validation","validationCode":"func validateConstraintLTarget(c *structs.Constraint) error {\n\tneedsTarget := c.Operand != \"distinct_hosts\" && c.Operand != \"\"\n\tif needsTarget && c.LTarget == \"\" {\n\t\treturn fmt.Errorf(\"constraint with operand %q requires an attribute (LTarget)\", c.Operand)\n\t}\n\treturn nil\n}","typeGuard":"func constraintHasAttribute(c *structs.Constraint) bool { return c != nil && c.LTarget != \"\" }","tryCatchPattern":null,"preventionTips":["Always pair an operator with its attribute; check Nomad docs for operators that don't need one (distinct_hosts, distinct_property).","Template constraint stanzas with the attribute line present.","Use `nomad job validate` before submission."],"tags":["nomad","constraint","validation"],"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"}