Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to ignore errors in datastore.Query.GetAll()?
    primarykey
    data
    text
    <p>I just started developing a GAE app with the Go runtime, so far it's been a pleasure. However, I have encountered the following setback:</p> <p>I am taking advantage of the flexibility that the datastore provides by having several different structs with different properties being saved with the same entity name ("Item"). The <a href="http://code.google.com/appengine/docs/go/datastore/reference.html" rel="nofollow">Go language datastore reference</a> states that "the actual types passed do not have to match between Get and Put calls or even across different App Engine requests", since entities are actually just a series of properties, and can therefore be stored in an appropriate container type that can support them.</p> <p>I need to query all of the entities stored under the entity name "Item" and encode them as JSON all at once. Using that entity property flexibility to my advantage, it is possible to store queried entities into an arbitrary <code>datastore.PropertyList</code>, however, the <code>Get</code> and <code>GetAll</code> functions return <code>ErrFieldMismatch</code> as an error when a property of the queried entities cannot be properly represented (that is to say, incompatible types, or simply a missing value). All of these structs I'm saving are user generated and most values are optional, therefore saving empty values into the datastore. There are no problems while saving these structs with empty values (datastore flexibility again), but there are when retrieving them.</p> <p>It is also stated in the datastore Go documentation, that it is up to the caller of the <code>Get</code> methods to decide if the errors returned due to empty values are ignorable, recoverable, or fatal. I would like to know how to properly do this, since just ignoring the errors won't suffice, as the destination structs (<code>datastore.PropertyList</code>) of my queries are not filled at all when a query results in this error.</p> <p>Thank you in advance, and sorry for the lengthy question.</p> <p>Update: Here is some code</p> <pre><code>query := datastore.NewQuery("Item") // here I use some Filter calls, as well as a Limit call and an Order call items := make([]datastore.PropertyList, 0) _, err := query.GetAll(context, &amp;items) // context has been obviously defined before if err != nil { // something to handle the error, which in my case, it's printing it and setting the server status as 500 } </code></pre> <p>Update 2: Here is some output</p> <p>If I use <code>make([]datastore.PropertyList, 0)</code>, I get this:</p> <pre><code>datastore: invalid entity type </code></pre> <p>And if I use <code>make(datastore.PropertyList, 0)</code>, I get this:</p> <pre><code>datastore: cannot load field "Foo" into a "datastore.Property": no such struct field </code></pre> <p>And in both cases (the first one I assume can be discarded) in <code>items</code> I get this:</p> <pre><code>[] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload