Skip to content

ArrayUnmarshaller: return None on nullable type instead of "NoneType object is not iterable" crash #276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion openapi_core/unmarshalling/schemas/unmarshallers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ def items_unmarshaller(self):

def __call__(self, value=NoValue):
value = super(ArrayUnmarshaller, self).__call__(value)

if value is None and self.schema.nullable:
return None
return list(map(self.items_unmarshaller, value))


Expand Down
21 changes: 21 additions & 0 deletions tests/unit/unmarshalling/test_unmarshal.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,27 @@ def test_array_valid(self, unmarshaller_factory):

assert result == value

def test_array_null(self, unmarshaller_factory):
schema = Schema(
'array',
items=Schema('integer'),
)
value = None

with pytest.raises(TypeError):
unmarshaller_factory(schema)(value)

def test_array_nullable(self, unmarshaller_factory):
schema = Schema(
'array',
items=Schema('integer'),
nullable=True,
)
value = None
result = unmarshaller_factory(schema)(value)

assert result is None

def test_array_of_string_string_invalid(self, unmarshaller_factory):
schema = Schema('array', items=Schema('string'))
value = '123'
Expand Down