Skip to content

Commit c309089

Browse files
authored
Merge pull request #276 from jgod/master
ArrayUnmarshaller: return None on nullable type instead of "NoneType object is not iterable" crash
2 parents e39a3f4 + 22a2771 commit c309089

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

Diff for: openapi_core/unmarshalling/schemas/unmarshallers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ def items_unmarshaller(self):
144144

145145
def __call__(self, value=NoValue):
146146
value = super(ArrayUnmarshaller, self).__call__(value)
147-
147+
if value is None and self.schema.nullable:
148+
return None
148149
return list(map(self.items_unmarshaller, value))
149150

150151

Diff for: tests/unit/unmarshalling/test_unmarshal.py

+21
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,27 @@ def test_array_valid(self, unmarshaller_factory):
352352

353353
assert result == value
354354

355+
def test_array_null(self, unmarshaller_factory):
356+
schema = Schema(
357+
'array',
358+
items=Schema('integer'),
359+
)
360+
value = None
361+
362+
with pytest.raises(TypeError):
363+
unmarshaller_factory(schema)(value)
364+
365+
def test_array_nullable(self, unmarshaller_factory):
366+
schema = Schema(
367+
'array',
368+
items=Schema('integer'),
369+
nullable=True,
370+
)
371+
value = None
372+
result = unmarshaller_factory(schema)(value)
373+
374+
assert result is None
375+
355376
def test_array_of_string_string_invalid(self, unmarshaller_factory):
356377
schema = Schema('array', items=Schema('string'))
357378
value = '123'

0 commit comments

Comments
 (0)