Skip to content

Commit

Permalink
[Issue apache#12486][Python Client]JsonSchema encoding is not idempot…
Browse files Browse the repository at this point in the history
…ent (apache#12490)

* fix JsonSchema, copy data out to prevent modifying the reference object,
check keys before deleting them

* add unit test, but cannot test due to compilation failure for cpp lib
  • Loading branch information
tsturzl authored Dec 7, 2021
1 parent 3986be6 commit 2df53da
Show file tree
Hide file tree
Showing 2 changed files with 402 additions and 400 deletions.
15 changes: 10 additions & 5 deletions pulsar-client-cpp/python/pulsar/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,16 @@ def _get_serialized_value(self, o):

def encode(self, obj):
self._validate_object_type(obj)
del obj.__dict__['_default']
del obj.__dict__['_required']
del obj.__dict__['_required_default']

return json.dumps(obj.__dict__, default=self._get_serialized_value, indent=True).encode('utf-8')
# Copy the dict of the object as to not modify the provided object via the reference provided
data = obj.__dict__.copy()
if '_default' in data:
del data['_default']
if '_required' in data:
del data['_required']
if '_required_default' in data:
del data['_required_default']

return json.dumps(data, default=self._get_serialized_value, indent=True).encode('utf-8')

def decode(self, data):
return self._record_cls(**json.loads(data))
Loading

0 comments on commit 2df53da

Please sign in to comment.