aquarat / google-api-go-client

Automatically exported from code.google.com/p/google-api-go-client
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Go datastore JSON api Indexed property always true #70

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
I was not sure where to post this question but I figured here was better than 
anywhere else. I've been working on a datastore client for the Google JSON API 
that wraps around the generated Go code here

https://godoc.org/code.google.com/p/google-api-go-client/datastore/v1beta2

My client eases the ability to construct compliant requests, entities, queries 
as well as provides some configuration and authentication assistance (much as 
the python an java libraries do). However, I ran into a wrinkle during some 
testing today. The core of it is how the omitempty tag on the Property struct's 
Indexed field is handled. The behavior is displayed in this play link.

What steps will reproduce the problem?

http://play.golang.org/p/4t8ZfyncgA

What is the expected output? What do you see instead?
Here is the output of the play
2009/11/10 23:00:00 A:{BlobValue:Not Omitted Indexed:false}
2009/11/10 23:00:00 Buff {"blobValue":"Not Omitted","indexed":false}
2009/11/10 23:00:00 See how the above has the Indexed property exported?
2009/11/10 23:00:00 Marshal exports it too {"blobValue":"Not 
Omitted","indexed":false}
2009/11/10 23:00:00 What happens if we add omitempty to the Indexed property?
2009/11/10 23:00:00 B:{BlobValue:Omitted Indexed:false}
2009/11/10 23:00:00 Buff {"blobValue":"Omitted"}
2009/11/10 23:00:00 See how the above does not have the Indexed property 
exported?
2009/11/10 23:00:00 Marshal does not export it either: {"blobValue":"Omitted"}

The issue is that the JSON api itself assumes that indexed = true if you do not 
explicitly set it to false in the JSON of your request. This is a problem 
because Marshaling the structs in the JSON API library will never give you an 
explicit indexed = false even if you have that set to false on the struct 
because the Indexed field is tagged 'omitempty'. I was trying to use the 
structs from the generated go but I don't see a way to work around this without 
just writing/copying my own verbatim copies of those structs so I can change 
that single tag. If the indexed field is not in the JSON of the request, 
specifically for a BlobValue, and the length of the BlobValue is > 500 bytes 
then you will get a 400 error response telling you that it can't save an 
indexed blob greater than 500 bytes (which is correct and in the docs). Is 
there anything I might be missing?

Here is a cleaned dump of the requests and response
http://pastebin.com/2t2Twy2Q

We have previously been constructing our own JSON for our entities and naively 
had the omitempty tag not on our Indexed property. Now that we're trying to 
make something that is more flexible we've run into this problem. I'm open to 
suggestions. Thank you for your time.

Ross

What version of the product are you using? Google Datastore JSON API v1betav2, 
Go 1.3.1
On what operating system? Linux & OSX

Original issue reported on code.google.com by ross.hen...@workiva.com on 6 Nov 2014 at 3:41