Timmmm
Timmmm

Reputation: 96547

"datastore: internal error: server returned the wrong number of entities" when retrieving non-existent object

With the go API for Google App Engine I try to retrieve a non-existent object:

func entityKey(c appengine.Context, name string) *datastore.Key {
    collectionKey := datastore.NewKey(c, "EntityCollection", "default_entitycollection", 0, nil)
    return datastore.NewKey(c, "Entity", name, 0, collectionKey)
}

//.....

var record EntityRecord // Some random type

key := entityKey(context, "This key does not exist")

err := datastore.Get(context, key, &record)

It returns the error:

datastore: internal error: server returned the wrong number of entities

Whereas I expect the much more obvious ErrNoSuchEntity. What gives?

This is on the local development server.

Upvotes: 2

Views: 643

Answers (1)

Caleb
Caleb

Reputation: 9458

The error is from here. Given the internal error bit this sounds like a bug to me. Reading the code it seems like it should return a slice with one GetResponse_Entity with a nil Entity field, but it's either returning too many GetResponse_Entitys or none.

You could tinker with the source code in:

go_appengine\goroot\src\pkg\appengine\datastore\datastore.go

Add some fmt.Printlns to this part:

req := &pb.GetRequest{
    Key: multiKeyToProto(c.FullyQualifiedAppID(), key),
}
res := &pb.GetResponse{}
if err := c.Call("datastore_v3", "Get", req, res, nil); err != nil {
    return err
}

Or perhaps try debugging with GDB. (though I'm not sure how you debug an app engine app)

You could also try clearing your local data store with:

dev_appserver.py --clear_datastore=yes myapp

But that's just a shot in the dark.

You might have better luck asking on the mailing list.

Upvotes: 1

Related Questions