Skip to content

Commit c623c68

Browse files
author
Chris Hoogeboom
authored
Fix the MappingProxyType error when converting schema to JSON (#930)
* Use the MappingProxyEncoder to encode the JSON * Use str instead * Remove unused import
1 parent 3146745 commit c623c68

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/confluent_kafka/avro/cached_schema_registry_client.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#
2020
# derived from https://github.com/verisign/python-confluent-schemaregistry.git
2121
#
22-
import json
2322
import logging
2423
import warnings
2524
from collections import defaultdict
@@ -213,7 +212,7 @@ def register(self, subject, avro_schema):
213212
url = '/'.join([self.url, 'subjects', subject, 'versions'])
214213
# body is { schema : json_string }
215214

216-
body = {'schema': json.dumps(avro_schema.to_json())}
215+
body = {'schema': str(avro_schema)}
217216
result, code = self._send_request(url, method='POST', body=body)
218217
if (code == 401 or code == 403):
219218
raise ClientError("Unauthorized access. Error code:" + str(code))
@@ -253,7 +252,7 @@ def check_registration(self, subject, avro_schema):
253252
url = '/'.join([self.url, 'subjects', subject])
254253
# body is { schema : json_string }
255254

256-
body = {'schema': json.dumps(avro_schema.to_json())}
255+
body = {'schema': str(avro_schema)}
257256
result, code = self._send_request(url, method='POST', body=body)
258257
if code == 401 or code == 403:
259258
raise ClientError("Unauthorized access. Error code:" + str(code))
@@ -374,7 +373,7 @@ def get_version(self, subject, avro_schema):
374373
return version
375374

376375
url = '/'.join([self.url, 'subjects', subject])
377-
body = {'schema': json.dumps(avro_schema.to_json())}
376+
body = {'schema': str(avro_schema)}
378377

379378
result, code = self._send_request(url, method='POST', body=body)
380379
if code == 404:
@@ -402,7 +401,7 @@ def test_compatibility(self, subject, avro_schema, version='latest'):
402401
"""
403402
url = '/'.join([self.url, 'compatibility', 'subjects', subject,
404403
'versions', str(version)])
405-
body = {'schema': json.dumps(avro_schema.to_json())}
404+
body = {'schema': str(avro_schema)}
406405
try:
407406
result, code = self._send_request(url, method='POST', body=body)
408407
if code == 404:

tests/avro/mock_registry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ def get_schema_by_id(self, req, groups):
100100
if not schema:
101101
return self._create_error("schema not found", 404)
102102
result = {
103-
"schema": json.dumps(schema.to_json())
103+
"schema": str(schema)
104104
}
105105
return (200, result)
106106

107107
def _get_identity_schema(self, avro_schema):
108108
# normalized
109-
schema_str = json.dumps(avro_schema.to_json())
109+
schema_str = str(avro_schema)
110110
if schema_str in self.schema_cache:
111111
return self.schema_cache[schema_str]
112112
self.schema_cache[schema_str] = avro_schema
@@ -150,7 +150,7 @@ def get_version(self, req, groups):
150150
schema_id = self.registry.get_id_for_schema(subject, avro_schema)
151151

152152
result = {
153-
"schema": json.dumps(avro_schema.to_json()),
153+
"schema": str(avro_schema),
154154
"subject": subject,
155155
"id": schema_id,
156156
"version": version
@@ -163,7 +163,7 @@ def get_latest(self, req, groups):
163163
if schema_id is None:
164164
return self._create_error("Not found", 404)
165165
result = {
166-
"schema": json.dumps(avro_schema.to_json()),
166+
"schema": str(avro_schema),
167167
"subject": subject,
168168
"id": schema_id,
169169
"version": version

0 commit comments

Comments
 (0)