Skip to content

Commit 3546419

Browse files
stanislavkozlovskiedenhill
authored andcommitted
cached_schema_registry_client: Fix bug where test_compatibility() would return None (instead of the expected False value) when unable to check compatibility (confluentinc#372, @Enether)
* cached_schema_registry_client: Fix bug where `test_compatibility()` would return `None` (instead of the expected `False` value) when unable to check compatibility * Also log response code * cached_schema_registry_client: Update get_compatibility() to the latest API specification
1 parent 41c0995 commit 3546419

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

confluent_kafka/avro/cached_schema_registry_client.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,8 @@ def test_compatibility(self, subject, avro_schema, version='latest'):
267267
elif code >= 200 and code <= 299:
268268
return result.get('is_compatible')
269269
else:
270-
log.error("Unable to check the compatibility")
271-
False
270+
log.error("Unable to check the compatibility: " + str(code))
271+
return False
272272
except Exception as e:
273273
log.error("_send_request() failed: %s", e)
274274
return False
@@ -301,17 +301,24 @@ def get_compatibility(self, subject=None):
301301
Get the current compatibility level for a subject. Result will be one of:
302302
303303
@:param: subject: subject name
304+
@:raises: ClientError: if the request was unsuccessful or an invalid compatibility level was returned
304305
@:return: 'NONE','FULL','FORWARD', or 'BACKWARD'
305306
"""
306307
url = '/'.join([self.url, 'config'])
307308
if subject:
308309
url += '/' + subject
309310

310311
result, code = self._send_request(url)
311-
if code >= 200 and code <= 299:
312-
compatibility = result.get('compatibility', None)
313-
314-
if not compatibility:
315-
compatibility = result.get('compatibilityLevel')
312+
is_successful_request = code >= 200 and code <= 299
313+
if not is_successful_request:
314+
raise ClientError('Unable to fetch compatibility level. Error code: %d' % code)
315+
316+
compatibility = result.get('compatibility', None)
317+
if compatibility not in VALID_LEVELS:
318+
if compatibility is None:
319+
error_msg_suffix = 'No compatibility was returned'
320+
else:
321+
error_msg_suffix = str(compatibility)
322+
raise ClientError('Invalid compatibility level received: %s' % error_msg_suffix)
316323

317324
return compatibility

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