{"record":{"id":"33c1c10b88258ca7","repo":"t8y2/dbx","slug":"lease-ttl-and-preservelease-cannot-be-specified-33c1c1","errorCode":null,"errorMessage":"lease, ttl, and preserveLease cannot be specified together","messagePattern":"lease, ttl, and preserveLease cannot be specified together","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"agents/drivers/etcd2-go/kv.go","lineNumber":200,"sourceCode":"\t}\n\tkey, err := keyBytesParam(params)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\tvalue, err := parseValueObject(rawObject(params, \"value\"))\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\texpectedModRevision := longOrNull(params, \"expectedModRevision\")\n\texpectedCreateRevision := longOrNull(params, \"expectedCreateRevision\")\n\tttlValue := longOrNull(params, \"ttl\")\n\tpreserveLease := boolOrDefault(params, \"preserveLease\", false)\n\n\tleaseValue := longOrNull(params, \"lease\")\n\thasLease := leaseValue != nil\n\thasTtl := ttlValue != nil\n\tif (hasLease && hasTtl) || (preserveLease && (hasLease || hasTtl)) {\n\t\treturn nil, errors.New(\"lease, ttl, and preserveLease cannot be specified together\")\n\t}\n\tif hasLease {\n\t\treturn nil, errors.New(\"ETCD_V2_LEASE_UNSUPPORTED: the etcd v2 API has no lease objects; use ttl instead\")\n\t}\n\tif preserveLease {\n\t\treturn nil, errors.New(\"ETCD_V2_LEASE_UNSUPPORTED: the etcd v2 API has no lease objects; use ttl instead\")\n\t}\n\tif expectedCreateRevision != nil && *expectedCreateRevision != 0 {\n\t\treturn nil, errors.New(\"ETCD_V2_CAS_UNSUPPORTED: the etcd v2 API cannot compare createdIndex; use expectedModRevision\")\n\t}\n\tif hasTtl && *ttlValue <= 0 {\n\t\treturn nil, errors.New(\"ttl must be a positive integer\")\n\t}\n\n\tform := url.Values{}\n\tform.Set(\"value\", value)\n\tif hasTtl {\n\t\tform.Set(\"ttl\", strconv.FormatInt(*ttlValue, 10))","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/t8y2/dbx/blob/c0390bff16418b651f4728520d99adf8ce48829a/agents/drivers/etcd2-go/kv.go#L182-L218","documentation":"The etcd v2 put handler accepts three mutually exclusive lease-related options: an explicit lease, a TTL, and preserveLease. Because the v2 API has no lease objects, at most one option may be given; specifying any two together is rejected with this error before any HTTP request is made.","triggerScenarios":"Calling put with lease AND ttl, preserveLease AND lease, or preserveLease AND ttl in the same request.","commonSituations":"Config layers merging defaults (a default ttl) with per-request lease options; migrating v3 code that passes lease IDs; a generic client that always forwards all optional fields.","solutions":["Send only one of lease, ttl, or preserveLease per put call","Drop lease fields entirely for v2 (see ETCD_V2_LEASE_UNSUPPORTED) and use ttl","Strip nil/default-valued lease options before dispatching so merged configs do not collide"],"exampleFix":"// before\n{ \"key\":\"k\", \"value\":\"v\", \"lease\": 123, \"ttl\": 60 }\n// after\n{ \"key\":\"k\", \"value\":\"v\", \"ttl\": 60 }","handlingStrategy":"validation","validationCode":"opts := 0\nif hasLease { opts++ }\nif hasTtl { opts++ }\nif preserveLease { opts++ }\nif opts > 1 { return errors.New(\"send at most one of lease, ttl, preserveLease\") }","typeGuard":null,"tryCatchPattern":"_, err := session.handle(ctx, \"put\", params)\nif err != nil && strings.Contains(err.Error(), \"cannot be specified together\") {\n\treturn fmt.Errorf(\"trim put options to a single lease mechanism; for v2 use ttl\")\n}","preventionTips":["Use one struct with mutually exclusive fields; validate before send","Strip zero-value/default lease options before building the request","Keep a v2 adapter that drops lease fields and maps them to ttl","Test merged-config output to catch accidental option collisions"],"tags":["etcd","validation","parameters","go"],"backgroundTag":"conflicting-parameters","analyzedSha":"c0390bff16418b651f4728520d99adf8ce48829a","analyzedAt":"2026-09-05T23:05:10.900Z","contentChangedAt":"2026-09-05T23:05:10.900Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}