Skip to content

Serialization error when encoding schema with subrecords in python client #3916

@yciabaud

Description

@yciabaud

It seems that the schema support in the client 2.3.0 on python 3.7 is not working with subrecords.

This example produces an error when encoding ():

"TypeError: Object of type MySubRecord is not JSON serializable"

import json
from pulsar.schema import Record, String, JsonSchema

def test_complex():
    class MySubRecord(Record):
        a = String()

    class Example(Record):
        sub = MySubRecord() # Test with instance

    r = Example(sub = MySubRecord( a = 'string' ))
    assert r.sub.a == 'string'

    s = JsonSchema(Example)

    # Produces "TypeError: Object of type MySubRecord is not JSON serializable"
    data = s.encode(r)

    assert json.loads(data)['sub']['a'] == 'string'

Is there something I missed in the implementation? I tested with AvroSchema with no success.

I expected the client to use a custom encoder that would have encoded the subrecord.

What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bugThe PR fixed a bug or issue reported a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions