Skip to content

Commit addc57b

Browse files
authored
Fix: handle null object correctly (singer-io#38)
* add unit test for null/empty dictionaries * handle null object correctly * bump version
1 parent 6fe6d71 commit addc57b

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55

66
setup(name="singer-python",
7-
version='3.1.0',
7+
version='3.1.1',
88
description="Singer.io utility library",
99
author="Stitch",
1010
classifiers=['Programming Language :: Python :: 3 :: Only'],

singer/transform.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ def _transform_anyof(self, data, schema, path):
124124
return False, None
125125

126126
def _transform_object(self, data, schema, path):
127+
# only a schema of "null" can match a null value
128+
# NB> This will not fail an empty dictionary, i.e. {}
129+
if data is None:
130+
return False, None
131+
127132
result = {}
128133
successes = []
129134
for key, value in data.items():

tests/test_transform.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,3 +214,12 @@ def test_unix_seconds_to_datetime(self):
214214
def test_unix_seconds_to_datetime(self):
215215
self.assertEqual(unix_milliseconds_to_datetime(0), '1970-01-01T00:00:00.000000Z')
216216
self.assertEqual(unix_milliseconds_to_datetime(1502722441000), '2017-08-14T14:54:01.000000Z')
217+
218+
def test_null_object_transform(self):
219+
schema = {"type": "object",
220+
"properties": {"addrs": {"type": ["null", "object"],
221+
"properties": {"city": {"type": "string"}}}}}
222+
none_data = {'addrs': None}
223+
self.assertDictEqual(none_data, transform(none_data, schema))
224+
empty_data = {'addrs': {}}
225+
self.assertDictEqual(empty_data, transform(empty_data, schema))

0 commit comments

Comments
 (0)