8000 Handle new values in API responses gracefully (for almost-GA clients) · Issue #1832 · googleapis/google-cloud-java · GitHub
[go: up one dir, main page]

Skip to content

Handle new values in API responses gracefully (for almost-GA clients) #1832

@lukesneeringer

Description

@lukesneeringer

There was a bug in the Node.js Vision client which was effectively that the client raised an exception if it ever got a key that it did not expect. This is relatively easy to do for any number of reasons:

# `raw_response` is a dict that came back from the API.
key_map = {
    'alphaObject': 'alpha_object',
    'betaObject': 'beta_object',
}
new_response = {}
for k, v in raw_response.iteritems():
    new_response[key_map[k]] = v

This is an anti-pattern, because it strongly assumes that you will never get a new key that is not already in your key map. If the API adds a gammaObject key and this (Python) code were to run, suddenly what used to work now raises KeyError.

The solution: Add unit tests in each spot where we transform an API response into a custom object to ensure that unexpected key-value pairs are either passed through or dropped.

Metadata

Metadata

Labels

api: datastoreIssues related to the Datastore API.api: loggingIssues related to the Cloud Logging API.api: storageIssues related to the Cloud Storage 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

    0