{"record":{"id":"0f76464ac715ae26","repo":"dgraph-io/dgraph","slug":"invalid-uid-with-value-0-for-key-v","errorCode":null,"errorMessage":"Invalid UID with value 0 for key: %v","messagePattern":"Invalid UID with value 0 for key: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"x/keys.go","lineNumber":573,"sourceCode":"\tk = k[sz:]\n\n\tswitch p.bytePrefix {\n\tcase ByteSchema, ByteType:\n\t\treturn p, nil\n\tdefault:\n\t}\n\n\tp.ByteType = k[0]\n\tk = k[1:]\n\n\tswitch p.ByteType {\n\tcase ByteData, ByteReverse:\n\t\tif len(k) < 8 {\n\t\t\treturn p, errors.Errorf(\"uid length < 8 for key: %q, parsed key: %+v\", key, p)\n\t\t}\n\t\tp.Uid = binary.BigEndian.Uint64(k)\n\t\tif p.Uid == 0 {\n\t\t\treturn p, errors.Errorf(\"Invalid UID with value 0 for key: %v\", key)\n\t\t}\n\t\tif !p.HasStartUid {\n\t\t\tbreak\n\t\t}\n\n\t\tif len(k) != 16 {\n\t\t\treturn p, errors.Errorf(\"StartUid length != 8 for key: %q, parsed key: %+v\", key, p)\n\t\t}\n\n\t\tk = k[8:]\n\t\tp.StartUid = binary.BigEndian.Uint64(k)\n\tcase ByteIndex:\n\t\tif !p.HasStartUid {\n\t\t\tp.Term = string(k)\n\t\t\tbreak\n\t\t}\n\n\t\tif len(k) < 8 {","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/x/keys.go#L555-L591","documentation":"Parse() in x/keys.go decodes Dgraph's binary key layout. For ByteData/ByteReverse keys the payload must contain a non-zero 8-byte big-endian UID; a zero UID means a malformed or corrupted key, so Parse refuses to return it.","triggerScenarios":"Calling Parse (directly or via IsDropOpKey, e.g. during a drop operation in checkAndGetDropOp) with a data-type key whose length is >= 8 but whose first 8 bytes decode to uint64(0).","commonSituations":"Corrupted badger key data, hand-crafted keys passed to IsDropOpKey, keys written by buggy or older Dgraph versions with unset UIDs, or test fixtures with zero-filled data keys.","solutions":["Dump the key with hex.Dump and verify the first 8 bytes are the intended non-zero UID","Regenerate the key through the proper Key/Schema encoding helpers instead of constructing it manually","Check for writers producing zero UIDs (uninitialized Uid fields) in your data path","If this arises during a drop op, inspect the posting list for corruption and consider restoring from backup"],"exampleFix":"// before: hand-built data key with zero UID\nkey := append([]byte{0x00}, make([]byte, 9)...)\nok, err := x.IsDropOpKey(key) // errors: Invalid UID with value 0\n// after: build keys via the library\nkey := x.IndexKey(attr, uid) // ensures valid non-zero UID","handlingStrategy":"validation","validationCode":"func validDataKey(key []byte) bool {\n  if len(key) < 9 { return false }\n  uid := binary.BigEndian.Uint64(key[1:9])\n  return uid != 0\n}\nif !validDataKey(key) { return fmt.Errorf(\"bad key: %x\", key) }\nok, err := x.IsDropOpKey(key)","typeGuard":"func hasNonZeroUid(key []byte) bool {\n  if len(key) < 9 { return false }\n  return binary.BigEndian.Uint64(key[1:9]) != 0\n}","tryCatchPattern":null,"preventionTips":["Always build keys via the package's Key helpers, never manual byte assembly","Log hex.Dump of keys that fail parsing before discarding","Add zero-UID checks where UIDs are assigned before writing keys"],"tags":["go","badger","key-parsing","dgraph"],"backgroundTag":"invalid-zero-uid-key","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}