Skip to content

BigTable Policy.etag is bytes (should be base64 str) #7369

@yonran

Description

@yonran

Environment details

  1. API: BigTable
  2. OS type and version: OSX
  3. Python version and virtual environment information: 3.7.0
  4. google-cloud-bigtable 0.32.1

Steps to reproduce

  1. Try to convert the to_api_repr() of a google.cloud.bigtable.policy.Policy to 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': […]}

Metadata

Metadata

Assignees

Labels

api: bigtableIssues related to the Bigtable API.priority: p2Moderately-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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions