bolt icon indicating copy to clipboard operation
bolt copied to clipboard

Deleting bucket after inserting a nil value

Open tg opened this issue 9 years ago • 2 comments

After executing the following steps in a single transaction:

  1. Create a bucket
  2. Add key with a nil value to the bucket
  3. Delete the bucket

I get the following error:

delete bucket: incompatible value

If value in point (2) is not nil, or deleting from a different transaction, everything works as expected.

tg avatar Mar 25 '16 23:03 tg

Code replicating the problem:

package main

import (
    "fmt"

    "github.com/boltdb/bolt"
)

func main() {
    db, _ := bolt.Open("/tmp/bolt.db", 0666, nil)
    defer db.Close()
    tx, _ := db.Begin(true)
    defer tx.Rollback()

    bucketName := []byte("oops")
    b, _ := tx.CreateBucket(bucketName)

    b.Put([]byte("key"), nil) // putting []byte{} works fine

    fmt.Println(tx.DeleteBucket(bucketName))
}

// Output:
// delete bucket: incompatible value

tg avatar Mar 26 '16 00:03 tg

This is still reproducible

cshubhamrao avatar Jan 02 '17 16:01 cshubhamrao