{"record":{"id":"b6f1e4e8d3f71957","repo":"hashicorp/nomad","slug":"distinct-property-must-have-an-allowed-count-of-1","errorCode":null,"errorMessage":"Distinct Property must have an allowed count of 1 or greater: %d < 1","messagePattern":"Distinct Property must have an allowed count of 1 or greater: (.+?) < 1","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nomad/structs/structs.go","lineNumber":10091,"sourceCode":"\t\tif _, err := regexp.Compile(c.RTarget); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Regular expression failed to compile: %v\", err))\n\t\t}\n\tcase ConstraintVersion:\n\t\tif _, err := version.NewConstraint(c.RTarget); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Version constraint is invalid: %v\", err))\n\t\t}\n\tcase ConstraintSemver:\n\t\tif _, err := semver.NewConstraint(c.RTarget); err != nil {\n\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Semver constraint is invalid: %v\", err))\n\t\t}\n\tcase ConstraintDistinctProperty:\n\t\t// If a count is set, make sure it is convertible to a uint64\n\t\tif c.RTarget != \"\" {\n\t\t\tcount, err := strconv.ParseUint(c.RTarget, 10, 64)\n\t\t\tif err != nil {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Failed to convert RTarget %q to uint64: %v\", c.RTarget, err))\n\t\t\t} else if count < 1 {\n\t\t\t\tmErr.Errors = append(mErr.Errors, fmt.Errorf(\"Distinct Property must have an allowed count of 1 or greater: %d < 1\", count))\n\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 == \"\" {","sourceCodeStart":10073,"sourceCodeEnd":10109,"githubUrl":"https://github.com/hashicorp/nomad/blob/482b49bf1aec006f089bcfc7e632d8f6ac303e5e/nomad/structs/structs.go#L10073-L10109","documentation":"A \"distinct_property\" constraint parsed its count successfully but the value is 0 (or otherwise below 1). Nomad requires an allowed count of at least 1, since the constraint exists to limit how many allocations may share a property value. Validation rejects the job.","triggerScenarios":"Submitting a job with distinct_property RTarget \"0\" (or \"00\", \"0x0\"-equivalent decimal 0), which parses to uint64 0 and fails the count < 1 check.","commonSituations":"Templated job generation where a loop variable defaulted to 0; intending to 'disable' the constraint by setting count 0 instead of removing it; copying config with count \"0\" left from a disabled example.","solutions":["Set the count RTarget to \"1\" or greater.","If you do not want the constraint, remove the distinct_property block entirely instead of setting count 0.","Fix the template/variable that produced 0 and re-submit."],"exampleFix":"// before\nconstraint {\n  attribute         = \"${attr.unique_id}\"\n  distinct_property = \"0\"\n}\n// after\nconstraint {\n  attribute         = \"${attr.unique_id}\"\n  distinct_property = \"1\"\n}","handlingStrategy":"validation","validationCode":"func validDistinctPropertyCount(target string) bool {\n  if target == \"\" { return true }\n  n, err := strconv.ParseUint(target, 10, 64)\n  return err == nil && n >= 1\n}","typeGuard":null,"tryCatchPattern":"count, err := strconv.ParseUint(target, 10, 64)\nif err != nil || count < 1 {\n  return fmt.Errorf(\"distinct_property count must be >= 1, got %q\", target)\n}","preventionTips":["Remove the constraint block instead of setting count 0 to disable it.","Guard template variables that feed the count against zero defaults.","Validate rendered jobs in CI with nomad job validate."],"tags":["nomad","constraint","distinct-property","job-validation"],"backgroundTag":"invalid-constraint-value","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"}