-
Notifications
You must be signed in to change notification settings - Fork 1.7k
BigTable Policy.etag is bytes (should be base64 str) #7369
Copy link
Copy link
Closed
Labels
api: bigtableIssues related to the Bigtable API.Issues related to the Bigtable API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Description
Environment details
- API: BigTable
- OS type and version: OSX
- Python version and virtual environment information: 3.7.0
- google-cloud-bigtable 0.32.1
Steps to reproduce
- Try to convert the
to_api_repr()of agoogle.cloud.bigtable.policy.Policyto json.
Code example
from google.cloud import bigtable
import json
client = bigtable.Client(admin=True)
(instances_list, failed_locations) = client.list_instances()
policy = instances_list[0].get_iam_policy()
json.dumps(policy.to_api_repr())Stack trace
Unlike other policies (such as the one returned from google.cloud.storage), etag is not a str (contrary to doc), and to_api_repr cannot be converted to json (contrary to doc), apparently because bigtable’s Policy passes _to_bytes(etag) to the superclass constructor.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type bytes is not JSON serializable
The to_api_repr() of a bigtable Policy is a dict containing binary bytes like {'etag': b'\x00 \x01', 'version': 0}, whereas the to_api_repr() of a Policy from google cloud storage is a dict whose etag is base64-encoded such as {'etag': 'CAU=', 'bindings': […]}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
api: bigtableIssues related to the Bigtable API.Issues related to the Bigtable API.priority: p2Moderately-important priority. Fix may not be included in next release.Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.Error or flaw in code with unintended results or allowing sub-optimal usage patterns.