GeezerVison is showing github.com — GeoPt not honoured · Issue #1065 · googleapis/google-cloud-python
Labels api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DescriptionWe have a record in the datastore which has the object type ndb.GeoPtProperty. This record was set via ndb from the app engine. Now we are running a script on GCE to modify one field in this record, without touching the original location point.
When the record is saved from gCloud API, the record looses it's GeoPtProperty.
Before:
> record.location
datastore_types.GeoPt(19.179167, 72.9640237)
After:
Activitydhermes commented on Aug 17, 2015 dhermes commented on Aug 17, 2015 @thinrhino Here is what I've just done:
from google.appengine.ext import ndb
class Foo(ndb.Model):
bar = ndb.GeoPtProperty()
g = ndb.GeoPt(10.0, 10.0)
f = Foo(bar=g)
f.put()
print(f)
which created key=Key('Foo', 5634472569470976).
Then in gcloud-python:
from gcloud import datastore
client = datastore.Client()
key = client.key('Foo', 5634472569470976)
entity = client.get(key)
print(entity)
which is
<Entity[{'kind': u'Foo', 'id': 5634472569470976L}] {u'bar': <Entity {u'y': 10.0, u'x': 10.0}>}>
So the data is still there, but I'm not sure the geopt part can be set from the Cloud Datastore API (I am fairly certain it can't). jgeewax commented on Aug 17, 2015 I believe this is doing what it should -- as GeoPt isn't something supported by the JSON API, but instead is an abstraction in DB / NDB
So under the hood, it looks like NDB is taking a GeoPt and turning into a pair of coordinates before saving via the API -- and then loading it into that property on the way out of the API as well.
If we get NDB running on top of the Cloud Datastore API this problem should go away as you'd just use NDB the whole time (see to #557). dhermes commented on Aug 17, 2015 Actually stepping into Connection.lookup and checking out the protobuf response, it seems the "meaning" is set on the GeoPt property:
found {
entity {
key {
partition_id {
dataset_id: "s~FOO"
}
path_element {
kind: "Foo"
id: 5634472569470976
}
}
property {
name: "bar"
value {
entity_value {
property {
name: "x"
value {
double_value: 10.0
indexed: false
}
}
property {
name: "y"
value {
double_value: 10.0
indexed: false
}
}
}
meaning: 9
}
}
}
}
The only real mention of "meaning" in the .proto file is
An entity value with meaning 9, 20 or 21 may be indexed.
so maybe we need to add support for setting "meaning" in these cases. dhermes commented on Aug 17, 2015 @jgeewax Thanks for hunting down the source, ndb actually sets the meaning:
p.set_meaning(entity_pb.Property.GEORSS_POINT)
and the list of meanings is defined in google.appengine.datastore.entity_pb. It looks like 20 and 21 are no longer meanings, but maybe they were at some point (I checked r525, r500, r450, r400 and r300 and didn't see any mention of them)? jgeewax commented on Aug 17, 2015 Yea we definitely need @pcostell to chime in on this -- I have no idea what the meaning value might mean in a broader sense. Hopefully we can use that..
Hypothetically, if that did exist, do you think gcloud.datastore should have a GeoPt data type? dhermes commented on Aug 17, 2015 @jgeewax It wouldn't be that hard to do. We discussed / dismissed implementing meaning in #265 and that was the end of it (AFAICT). pcostell commented on Aug 17, 2015 v1beta2 doesn't have a specific geopt field, which is why it is represented using this "legacy-supported" type (an entity_value with a meaning). However, v1beta3 does have a specific geopt which will be populated instead.
In general, fields with the meaning should always be preserved, however we should never be creating new fields with meanings set (which is why in the API they are not actually explained). You should still be able to edit this field in the same way you can edit an entity_value. dhermes commented on Aug 17, 2015 @pcostell When can we start using v1beta3? What should we do about this in the meantime? pcostell commented on Aug 17, 2015 "Soon". This should still work in v1beta2, as the property should still be editable as a normal entity_value. You should never be setting the meaning, but you should be persisting an existing meaning. So if users can edit an entity value, this should work. dhermes commented on Aug 17, 2015 Is it worth making a change to preserve to meaning if we are just going to ditch meanings all together "soon"? (It really depends on your judgment of how soon.) We just did a release 8/12 so even if we made a fix it may not be in a release for another 14-21 days . pcostell commented on Aug 17, 2015 Yes, we should always be preserving the meaning. There are other legacy properties that will still require meaning even after the v1beta3 launch. dhermes commented on Aug 17, 2015 OK great.
Secondary question, what are the mysterious enums at 20 and 21 for meaning?
An entity value with meaning 9, 20 or 21 may be indexed.
pcostell commented on Aug 17, 2015 Secret :-). We don't want clients of the gcloud libraries actually depending on meaning value (they should only be persisting them).
At the moment (but we reserve the right to change them): 9 is a GeoPt which is exists in the geo-range (lat/lng), 21 is an "invalid" geopoint (any range, so really just a point), and 20 represents an App Engine UserProperty. dhermes commented on Nov 18, 2015 dhermes commented on Nov 23, 2015 FYI I'm closing in on a fix for this (also fixes #1206 as a side effect) added a commit that references this issue on Nov 24, 2015This issue will close once commit aa7e011 is merged into the 'master' branch.aa7e011 added 2 commits that reference this issue on Dec 17, 2015This issue will close once commit 20c1aed is merged into the 'master' branch.20c1aed This issue will close once commit 5873266 is merged into the 'master' branch.5873266 dhermes commented on Dec 21, 2015 @thinrhino Sorry for the delay but this has been fixed and will hopefully be in a release soon.
From my App Engine app (using the remote api) I made a property with lots of meanings (including geo point):
from google.appengine.ext import ndb
class Foo2(ndb.Model):
_use_cache = False
_use_memcache = False
b1 = ndb.BlobProperty(compressed=True)
class Foo(ndb.Model):
_use_cache = False
_use_memcache = False
b1 = ndb.BlobProperty(compressed=True)
b2 = ndb.BlobProperty(compressed=True, repeated=True)
t1 = ndb.TextProperty(compressed=False, indexed=False)
geo = ndb.GeoPtProperty()
struct_p = ndb.StructuredProperty(Foo2)
loc_struct_p = ndb.LocalStructuredProperty(Foo2)
f1 = Foo2(b1='hey')
f2 = Foo(id=1234, b1='b1', b2=['hi', 'ok'],
t1='t1', geo=ndb.GeoPt(52.37, 4.88),
struct_p=f1, loc_struct_p=f1)
f2.put()
and then I retrieved it with gcloud-python
>>> import os
>>> import pprint
>>> from gcloud import datastore
>>> os.environ.pop('GOOGLE_APPLICATION_CREDENTIALS')
'path/redacted'
>>> client = datastore.Client(dataset_id='gae-app-id')
>>> key = client.key('Foo', 1234)
>>> entity = client.get(key)
>>> pprint.pprint(entity._meanings)
{u'b1': (22, 'x\x9cK2\x04\x00\x00\xf7\x00\x94'),
u'b2': (22,
['x\x9c\xcb\xc8\x04\x00\x01;\x00\xd2',
'x\x9c\xcb\xcf\x06\x00\x01K\x00\xdb']),
u'geo': (9, <Entity {u'y': 4.88, u'x': 52.37}>),
u'struct_p.b1': (22, 'x\x9c\xcbH\xad\x04\x00\x02~\x01G'),
u't1': (15, u't1')}
>>> sorted(entity._meanings.keys())
[u'b1', u'b2', u'geo', u'struct_p.b1', u't1']
>>> sorted(entity.keys())
[u'b1', u'b2', u'geo', u'loc_struct_p', u'struct_p.b1', u't1']
>>> entity['geo']._meanings
{}
>>> entity['geo']
<Entity {u'y': 4.88, u'x': 52.37}>
>>> entity['loc_struct_p']._meanings
{u'b1': (22, 'x\x9c\xcbH\xad\x04\x00\x02~\x01G')}
>>> entity['loc_struct_p']
<Entity {u'b1': 'x\x9c\xcbH\xad\x04\x00\x02~\x01G'}>
even more, I made a change to the geo point (and sent to backend) and retrieved again to make sure they were identical
>>> entity['geo']['x'] = 3.14
>>> client.put(entity)
>>> entity2 = client.get(key)
>>> entity == entity2
True
>>> entity._meanings == entity2._meanings
True
>>> client.delete(entity.key)
(I also verified in the App Engine datastore viewer that the geo point change went through as expected) thinrhino commented on Dec 22, 2015 @dhermes thanks a lot. Will check it out soon.
MetadataMetadataapi: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. DevelopmentNo branches or pull requestsIssue actions
|