Skip to content

Commit f822e44

Browse files
authored
Fix KeyError for unsupported annotation types. (#2961)
* Fix KeyError for unsupported annotation types.
1 parent 3584917 commit f822e44

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

vision/google/cloud/vision/annotations.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def from_api_repr(cls, response):
9191
_KEY_MAP[feature_type]: _entity_from_response_type(
9292
feature_type, annotation)
9393
for feature_type, annotation in six.iteritems(response)
94+
if feature_type in _KEY_MAP
9495
}
9596
return cls(**annotations)
9697

vision/unit_tests/test_annotations.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@ def test_ctor(self):
6666
self.assertEqual(annotations.safe_searches, [True])
6767
self.assertEqual(annotations.texts, [True])
6868

69+
def test_unsupported_http_annotation(self):
70+
returned = {
71+
'responses': [
72+
{'someMadeUpAnnotation': None},
73+
],
74+
}
75+
annotation = self._get_target_class().from_api_repr(returned)
76+
self.assertIsInstance(annotation, self._get_target_class())
77+
6978
def test_from_pb(self):
7079
from google.cloud.vision.likelihood import Likelihood
7180
from google.cloud.vision.safe_search import SafeSearchAnnotation

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy