diff --git a/vision/google/cloud/vision/annotations.py b/vision/google/cloud/vision/annotations.py index a19527a96c11..2348d2361731 100644 --- a/vision/google/cloud/vision/annotations.py +++ b/vision/google/cloud/vision/annotations.py @@ -91,6 +91,7 @@ def from_api_repr(cls, response): _KEY_MAP[feature_type]: _entity_from_response_type( feature_type, annotation) for feature_type, annotation in six.iteritems(response) + if feature_type in _KEY_MAP } return cls(**annotations) diff --git a/vision/unit_tests/test_annotations.py b/vision/unit_tests/test_annotations.py index 68a270e3122d..2a5fb5b8ca92 100644 --- a/vision/unit_tests/test_annotations.py +++ b/vision/unit_tests/test_annotations.py @@ -66,6 +66,15 @@ def test_ctor(self): self.assertEqual(annotations.safe_searches, [True]) self.assertEqual(annotations.texts, [True]) + def test_unsupported_http_annotation(self): + returned = { + 'responses': [ + {'someMadeUpAnnotation': None}, + ], + } + annotation = self._get_target_class().from_api_repr(returned) + self.assertIsInstance(annotation, self._get_target_class()) + def test_from_pb(self): from google.cloud.vision.likelihood import Likelihood from google.cloud.vision.safe_search import SafeSearchAnnotation