9

here is my struct:

type AreaPrerequisite struct {
    SideQuestId   int // 
    SideQuestProg int // progress
}

type AreaInfo struct {
    Id                int              `datastore:""`
    Name              string           `datastore:",noindex"`
    ActionPoint       int              `datastore:",noindex"`
    Prerequisite      AreaPrerequisite `datastore:",noindex"`

    // ignored:
    DsMonsters        []byte           `datastore:"-"`
    DsStages          []byte           `datastore:"-"`
    Monsters          AreaMonsters     `datastore:"-"`
    Stages            []*StageEntry    `datastore:"-"`
}

and my put() call:

key := datastore.NewKey(c, "Area", "", int64(pArea.Id), nil)
_, err := datastore.Put(c, key, *pArea)
if err != nil {
    return err
}

It gives me the following error when try to put to DS:

datastore: invalid entity type

I checked the doc: https://developers.google.com/appengine/docs/go/datastore/reference

datastore:"-" should mark some non-supported fields ignored by datastore. Don't know why it is failing.

1
  • Have you put some data with the same "Area" kind before ? If you have updated your struct after putting some data, the two representations might conflict and produce an error. Commented Aug 16, 2013 at 17:26

2 Answers 2

16

I found that I accidentally added * to pArea as arg to put() so it is passing a value instead of pointer, causing invalid entity type error.

Sign up to request clarification or add additional context in comments.

2 Comments

Sir, you saved me too.
I encountered the same problem, but using PropertyList. Apparently if you pass in a PropertyList it also has to be a pointer not a value. stackoverflow.com/q/30792119/101923
4

I've also run into that same problem, in my case I didn't put & before the entity to be putted.

key := datastore.NewKey(c, "Area", "", int64(pArea.Id), nil)
_, err := datastore.Put(c, key, &pArea)
if err != nil {
    return err
}

Notice the & before &pArea

1 Comment

This was quite helpful. I actually added & to the object creation, then it can be omitted in the put call. E.G. myObj := &MyObj{} vs myObj := MyObj{}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.