Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Projection list does not support class attributes #212

Closed
chmoder opened this issue Sep 27, 2019 · 0 comments · Fixed by #214
Closed

Projection list does not support class attributes #212

chmoder opened this issue Sep 27, 2019 · 0 comments · Fixed by #214
Assignees
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@chmoder
Copy link
Contributor

chmoder commented Sep 27, 2019

Environment details

  1. Python 3.7.3
  2. google-cloud-ndb 0.1.0

Steps to reproduce

  1. ? Query with a projection list of ndbModel class attributes like this https://cloud.google.com/appengine/docs/standard/python/ndb/projectionqueries

Code example

class FooModel(ndb.Model):
    foo_attr = ndb.StringProperty()

FooModel.query(projection=[FooModel.foo_attr]).fetch()

Stack trace

ERROR:root:StringProperty('company', kind='Company') has type StringProperty, but expected one of: bytes, unicode
Traceback (most recent call last):
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/webapp2.py", line 604, in dispatch
    return method(*args, **kwargs)
  File "/Users/tcross/development/csgapi37/med_supp.py", line 684, in get
    return self.get_our_companies(keys_only)
  File "/Users/tcross/development/csgapi37/med_supp.py", line 654, in get_our_companies
    our_companies = pool.map(callback, query)
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/pool.py", line 268, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
  File "/usr/local/Cellar/python/3.7.3/Frameworks/Python.framework/Versions/3.7/lib/python3.7/multiprocessing/pool.py", line 383, in _map_async
    iterable = list(iterable)
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 596, in next
    if not self.has_next():
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 516, in has_next
    return self.has_next_async().result()
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 191, in result
    self.check_success()
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 138, in check_success
    raise self._exception
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 297, in _advance_tasklet
    type(error), error, error.__traceback__
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 534, in has_next_async
    result_set.has_next_async() for result_set in self._result_sets
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 297, in _advance_tasklet
    type(error), error, error.__traceback__
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 263, in has_next_async
    yield self._next_batch()  # First time
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 297, in _advance_tasklet
    type(error), error, error.__traceback__
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 291, in _next_batch
    response = yield _datastore_run_query(query)
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/tasklets.py", line 301, in _advance_tasklet
    yielded = self.generator.send(send_value)
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 830, in _datastore_run_query
    query_pb = _query_to_protobuf(query)
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 737, in _query_to_protobuf
    for name in query.projection
  File "/Users/tcross/development/virtual-environments/csgapi37/lib/python3.7/site-packages/google/cloud/ndb/_datastore_query.py", line 737, in <listcomp>
    for name in query.projection
TypeError: StringProperty('company', kind='Company') has type StringProperty, but expected one of: bytes, unicode
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Sep 28, 2019
chrisrossi pushed a commit that referenced this issue Oct 1, 2019
Cloud datastore needs projection and distinct properties to be strings.  This commit sets the converted properties so they may be used by the rest of the query. (Fixes #212)
@chrisrossi chrisrossi added 🚨 This issue needs some love. and removed triage me I really want to be triaged. labels Oct 1, 2019
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label Apr 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p1 Important issue which blocks shipping the next release. Will be fixed prior to next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants