"datastore: dst has invalid type"

625 views
Skip to first unread message

Tomi Hiltunen

unread,
Jul 10, 2013, 3:16:26 AM7/10/13
to golan...@googlegroups.com
Hi,

I'm trying to load a bunch of Debate structs from the GAE datastore using the GetMulti function. Datastore can perform the simple Get for the individual entities with the same keys. For the GetMulti I get an error message saying "datastore: dst has invalid type".

var debates []Debate
if err := datastore.GetMulti(c, debateKeys, &debates); err != nil {
return nil, err
}

The Debate struct looks like this:

type Debate struct {
// General
Id string
Topic string
Creator int64
Type int64
CustomPositive string
CustomNegative string

// Status
Status int64
CreatedAt time.Time
UpdatedAt time.Time
ClosedAt time.Time

// Participants
Participants int64

// Arguments
Arguments []Argument
}

I suspect it has to do with the list of Argument type structs nested inside. Though, all the Arguments contain only properties supported by the datastore. And the simple Get function does work on these guys.

Any thoughts?


Dave Cheney

unread,
Jul 10, 2013, 3:24:18 AM7/10/13
to Tomi Hiltunen, golan...@googlegroups.com
You haven't shown the definition for the Argument type. 
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Tomi Hiltunen

unread,
Jul 10, 2013, 3:25:45 AM7/10/13
to golan...@googlegroups.com, Tomi Hiltunen

type Argument struct {
// General
Id string
Text string
Creator int64
CreatedAt time.Time
IsPositive bool

// Seconders
Seconders int64
}

Dave Cheney

unread,
Jul 10, 2013, 3:41:07 AM7/10/13
to Tomi Hiltunen, golan...@googlegroups.com, Tomi Hiltunen
Weird. Sorry if I missed that before. I wonder if it is the time.Time.Location field that is leaking that field in there. 

Tomi Hiltunen

unread,
Jul 10, 2013, 3:49:16 AM7/10/13
to golan...@googlegroups.com, Tomi Hiltunen

Nah, it wasn't there yet. Apparently this online UI mistook it as a quote.

time.Time should be a supported datastore property type. This only happens on GetMulti. Normal Get works just fine. The case here is that I'm trying to pull all the debates where the current user has participated. This includes pulling the participation details to get the debate keys. When I have the right keys, I use GetMulti to get the corresponding debates. This is tricky, but I think I need to make changes to the data structure to get around this issue.

David Symonds

unread,
Jul 10, 2013, 5:16:40 AM7/10/13
to Tomi Hiltunen, golang-nuts

Try fetching into []*Debate instead.

Tomi Hiltunen

unread,
Jul 10, 2013, 5:22:02 AM7/10/13
to golan...@googlegroups.com, Tomi Hiltunen
Hi David,

I tried that also. I got a different error stating "cannot use &debates (type *[]*Debate) as type *[]Debate in return argument"

- Tom



keskiviikko, 10. heinäkuuta 2013 12.16.40 UTC+3 David Symonds kirjoitti:

Try fetching into []*Debate instead.

Tomi Hiltunen

unread,
Jul 10, 2013, 5:25:52 AM7/10/13
to golan...@googlegroups.com, Tomi Hiltunen

Hi David,

I just realized my mistake on the last comment. I fixed the return values of the function, and now I'm back to datastore errors: "datastore: invalid entity type"

Tomi Hiltunen

unread,
Jul 10, 2013, 5:32:00 AM7/10/13
to golan...@googlegroups.com, Tomi Hiltunen

I was too quick to comment. It is working now as it is expected to. Here's how it looks now:

Note: debateKeys ==> []*datastore.Key

// Initiate debate interface.
debates := make([]*Debate, len(debateKeys))
for idx, _ := range debates {
debates[idx] = &Debate{}
}
// Get the actual debates from the datastore
if err := datastore.GetMulti(c, debateKeys, debates); err != nil {
return nil, err
}

Without the for-loop, it will give a "invalid entity" error from the datastore.

Thanks for helping me figure this out! :)

David Symonds

unread,
Jul 10, 2013, 5:47:35 AM7/10/13
to Tomi Hiltunen, golan...@googlegroups.com
Actually all you should need to do is

debates := make([]Debate, len(debateKeys))

See the docs: https://developers.google.com/appengine/docs/go/datastore/reference#GetMulti

Tomi Hiltunen

unread,
Jul 10, 2013, 6:18:33 AM7/10/13
to golan...@googlegroups.com, Tomi Hiltunen

I changed it to what you described and it works well. 

I had it like that at one point, though, but still got the "invalid type" error. Perhaps it was some browser caching or build issue... or just too much coffee. :)

Thanks for your time.

Cheers,
Tomi
Reply all
Reply to author
Forward
0 new messages