Skip to content

Commit

Permalink
fix: make sure SequenceSchema creates avro defined values (jpmorganch…
Browse files Browse the repository at this point in the history
  • Loading branch information
dada-engineer committed Mar 19, 2024
1 parent 90c9bc6 commit f457690
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
5 changes: 2 additions & 3 deletions src/py_avro_schema/_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -567,13 +567,12 @@ def data(self, names: NamesType) -> JSONObj:
"items": self.items_schema.data(names=names),
}

def make_default(self, py_default: collections.abc.Sequence) -> collections.abc.Sequence:
def make_default(self, py_default: collections.abc.Sequence) -> JSONArray:
"""Return an Avro schema compliant default value for a given Python Sequence
:param py_default: The Python sequence to generate a default value for.
"""
origin = get_origin(self.py_type) or self.py_type
return origin(self.items_schema.make_default(item) for item in py_default)
return [self.items_schema.make_default(item) for item in py_default]


class DictSchema(Schema):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -834,7 +834,7 @@ class PyType:
expected = {
"fields": [
{"default": ["foo", "bar"], "name": "field_a", "type": {"items": "string", "type": "array"}},
{"default": ("foo", "bar"), "name": "field_b", "type": {"items": "string", "type": "array"}},
{"default": ["foo", "bar"], "name": "field_b", "type": {"items": "string", "type": "array"}},
],
"name": "PyType",
"type": "record",
Expand Down

0 comments on commit f457690

Please sign in to comment.