Skip to content

Commit 0d9988b

Browse files
committed
fix(serializer): skip None values in config and registry
Other config items use this and there was a probelm where config:unset was getting caught on trying to validate that PORT was numeric
1 parent 4fcb794 commit 0d9988b

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

rootfs/api/serializers.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class Meta:
135135

136136
def validate_values(self, data):
137137
for key, value in data.items():
138+
if value is None: # use NoneType to unset an item
139+
continue
140+
138141
if not re.match(CONFIGKEY_MATCH, key):
139142
raise serializers.ValidationError(
140143
"Config keys must start with a letter or underscore and "
@@ -239,6 +242,9 @@ def validate_tags(self, data):
239242

240243
def validate_registry(self, data):
241244
for key, value in data.items():
245+
if value is None: # use NoneType to unset an item
246+
continue
247+
242248
if not re.match(CONFIGKEY_MATCH, key):
243249
raise serializers.ValidationError(
244250
"Config keys must start with a letter or underscore and "

rootfs/api/tests/test_config.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,17 @@ def test_config(self, mock_requests):
106106
self.assertEqual(response.status_code, 201, response.data)
107107
self.assertNotIn('NEW_URL1', json.dumps(response.data['values']))
108108

109+
# set a port and then unset it to make sure validation ignores the unset
110+
body = {'values': json.dumps({'PORT': '5000'})}
111+
response = self.client.post(url, body)
112+
self.assertEqual(response.status_code, 201, response.data)
113+
self.assertIn('PORT', response.data['values'])
114+
115+
body = {'values': json.dumps({'PORT': None})}
116+
response = self.client.post(url, body)
117+
self.assertEqual(response.status_code, 201, response.data)
118+
self.assertNotIn('PORT', response.data['values'])
119+
109120
# disallow put/patch/delete
110121
response = self.client.put(url)
111122
self.assertEqual(response.status_code, 405, response.data)

0 commit comments

Comments
 (0)