GeezerVison is showing github.com — Support 'blob_value' / 'blob_key_value' in datastore protobufs · Issue #233 · googleapis/google-cloud-python
Support 'blob_value' / 'blob_key_value' in datastore protobufs #233DescriptionIn addition to the scalar types we already support, there are the following value types we don't yet
support:
Activitydhermes commented on Oct 9, 2014 This is something we could check in an automated fashion:
>>> from gcloud.datastore import datastore_v1_pb2 as pb2
>>> for attr in dir(pb2.Value):
... if attr[0] == attr[0].lower() and attr[0] != '_':
... print attr
...
blob_key_value
blob_value
boolean_value
double_value
entity_value
indexed
integer_value
key_value
list_value
meaning
string_value
timestamp_microseconds_value
or
>>> for key in sorted(pb2._VALUE.fields_by_name.keys()):
... print key
...
blob_key_value
blob_value
boolean_value
double_value
entity_value
indexed
integer_value
key_value
list_value
meaning
string_value
timestamp_microseconds_value tseaver commented on Oct 16, 2014 ContributorAuthor More actions Note that handling 'blob_value' values will require us to think harder about handling "bytes" (marshalled via 'blob_value') vs. "text" (marshalled via 'string_value'). At the moment, we rather sloppily conflate handling both Python2 'str' and 'unicode' via 'string_value'. added this to the This milestone has been deleted milestone on Oct 17, 2014silvolu commented on Oct 18, 2014 @tseaver as you mentioned in #157, we should raise exceptions after the value types coverage is complete. silvolu commented on Oct 18, 2014 tseaver commented on Oct 18, 2014 ContributorAuthor More actions That will get tricksy:
- 'blob_value' should map to 'str' / 'bytes' in Python2, and 'bytes' in Python3
- 'string_value' should map to 'unicode' in Python2, and 'str' in Python3
Right now:
>>> from gcloud.datastore._helpers import _get_protobuf_attribute_and_value
>>> _get_protobuf_attribute_and_value(b'foo')
('string_value', 'foo')
>>> _get_protobuf_attribute_and_value(u'foo')
('string_value', u'foo')
>>> _get_protobuf_attribute_and_value('foo')
('string_value', 'foo')
which can't be right, long-term. It should be (under Python2):
>>> _get_protobuf_attribute_and_value(b'foo')
('blob_value', 'foo')
>>> _get_protobuf_attribute_and_value(u'foo')
('string_value', u'foo')
>>> _get_protobuf_attribute_and_value('foo')
('blob_value', 'foo')
and under Py3k:
>>> _get_protobuf_attribute_and_value(b'foo')
('blob_value', 'foo')
>>> _get_protobuf_attribute_and_value('foo')
('string_value', u'foo')
>>> _get_protobuf_attribute_and_value('foo')
('string_value', 'foo')
OTOH, '_get_value_from_value_pb' looks right:
>>> from gcloud.datastore.datastore_v1_pb2 import Value
>>> v = Value()
>>> v.string_value = 'abc'
>>> from gcloud.datastore._helpers import _get_value_from_value_pb
>>> _get_value_from_value_pb(v)
u'abc'
We'd like for the following to work:
>>> vb = Value()
>>> vb.blob_value = b'abc'
>>> _get_value_from_value_pb(vb)
'abc'
but it currently returns None. tseaver commented on Oct 18, 2014 ContributorAuthor More actions Changing to use 'blob_value' for bytes / native str in Python2 will be the one which confounds users expectations. dhermes commented on Oct 18, 2014 Indeed. I wonder if people have done things to deal with this in other libraries. Potentially encoding/decoding to ASCII or something similar? silvolu commented on Oct 18, 2014 tseaver commented on Oct 18, 2014 ContributorAuthor More actions tseaver commented on Oct 20, 2014 ContributorAuthor More actions
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|