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.

Dan McGrath
  • 41,220
  • 11
  • 99
  • 130
Nick
  • 783
  • 7
  • 21
  • 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. – val Aug 16 '13 at 17:26

2 Answers2

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.

Jay
  • 19,649
  • 38
  • 121
  • 184
Nick
  • 783
  • 7
  • 21
  • Sir, you saved me too. – Ali Nov 03 '14 at 12:20
  • 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. http://stackoverflow.com/q/30792119/101923 – Tim Swast Jun 11 '15 at 21:58
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

Ido Ran
  • 10,584
  • 17
  • 80
  • 143
  • 1
    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{} – Joey Roosing Sep 24 '16 at 21:37