GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GeoPt not honoured · Issue #1065 · googleapis/google-cloud-python

GeoPt not honoured #1065

New issue
Copy link
New issue
Copy link
Closed
Closed
GeoPt not honoured#1065
Copy link
Assignees
dhermes
Labels
api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@thinrhino
thinrhino
opened on Aug 17, 2015
Issue body actions

We 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:

> record.location
>

Activity

Next
  1. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    /cc @pcostell

  2. dhermes
    added
    api: datastoreIssues related to the Datastore API.
    on Aug 17, 2015
  3. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    @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).

  4. jgeewax commented on Aug 17, 2015

    @jgeewax
    jgeewax
    on Aug 17, 2015
    Contributor
    More actions

    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

    • GeoPt data type: https://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/api/datastore_types.py?r=503#877
    • GeoPtProperty in NDB: https://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/ndb/model.py?r=503#1748

    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).

  5. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    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.

  6. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    @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)?

  7. jgeewax commented on Aug 17, 2015

    @jgeewax
    jgeewax
    on Aug 17, 2015
    Contributor
    More actions

    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?

  8. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    @jgeewax It wouldn't be that hard to do. We discussed / dismissed implementing meaning in #265 and that was the end of it (AFAICT).

  9. pcostell commented on Aug 17, 2015

    @pcostell
    pcostell
    on Aug 17, 2015
    Contributor
    More actions

    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.

  10. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    @pcostell When can we start using v1beta3? What should we do about this in the meantime?

  11. pcostell commented on Aug 17, 2015

    @pcostell
    pcostell
    on Aug 17, 2015
    Contributor
    More actions

    "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.

  12. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    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 .

  13. pcostell commented on Aug 17, 2015

    @pcostell
    pcostell
    on Aug 17, 2015
    Contributor
    More actions

    Yes, we should always be preserving the meaning. There are other legacy properties that will still require meaning even after the v1beta3 launch.

  14. dhermes commented on Aug 17, 2015

    @dhermes
    dhermes
    on Aug 17, 2015
    Contributor
    More actions

    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.

  15. pcostell commented on Aug 17, 2015

    @pcostell
    pcostell
    on Aug 17, 2015
    Contributor
    More actions

    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.

  16. 23 remaining items

  17. dhermes commented on Nov 18, 2015

    @dhermes
    dhermes
    on Nov 18, 2015
    Contributor
    More actions

    Thanks Patrick!

  18. dhermes commented on Nov 23, 2015

    @dhermes
    dhermes
    on Nov 23, 2015
    Contributor
    More actions

    FYI I'm closing in on a fix for this (also fixes #1206 as a side effect)

  19. dhermes
    added a commit that references this issue on Nov 24, 2015

    Properly handling entity meanings in datastore.

    This issue will close once commit aa7e011 is merged into the 'master' branch.
    aa7e011
  20. dhermes
    added 2 commits that reference this issue on Dec 17, 2015

    Properly handling entity meanings in datastore.

    This issue will close once commit 20c1aed is merged into the 'master' branch.
    20c1aed

    Properly handling entity meanings in datastore.

    This issue will close once commit 5873266 is merged into the 'master' branch.
    5873266
  21. dhermes
    closed this as completedin #1241on Dec 21, 2015
  22. dhermes commented on Dec 21, 2015

    @dhermes
    dhermes
    on Dec 21, 2015
    Contributor
    More actions

    @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)

  23. thinrhino commented on Dec 22, 2015

    @thinrhino
    thinrhino
    on Dec 22, 2015
    Author
    More actions

    @dhermes thanks a lot. Will check it out soon.

  24. JustinBeckwith
    assigned
    dhermes
    on Feb 1, 2021
  25. parthea
    added 3 commits that reference this issue on Nov 24, 2025

    fix: suppress type error for fallback def of OptionalRetry (#1065)

    de07423

    chore(deps): update dependency idna to v3.7 [security] (#1065)

    6c4cac9

    chore: update sys test creds (#1065)

    83665c8
  26. parthea
    added 2 commits that reference this issue on Feb 20, 2026

    feat: Add support for python 3.14 (#1065)

    a802fe3

    chore: librarian release pull request: 20251215T134006Z (#1066)

    1485e4c
  27. parthea
    added a commit that references this issue on Mar 9, 2026

    docs: samples and tests for auto-generated createDatabase and createI…

    fae73c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @dhermes
    dhermes

Labels

api: datastoreIssues related to the Datastore API.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.