misc: don't crash on json data sources using lists (#46067)

This commit is contained in:
Frédéric Péters 2020-08-25 14:00:16 +02:00
parent 52800f4173
commit 90834b9402
2 changed files with 9 additions and 0 deletions

View File

@ -177,6 +177,13 @@ def test_json_datasource(requests_pub, http_requests):
json_file.close()
assert data_sources.get_items(datasource) == []
# json file not using dictionaries
get_request().datasources_cache = {}
json_file = open(json_file_path, 'w')
json.dump({'data': [['1', 'foo'], ['2', 'bar']]}, json_file)
json_file.close()
assert data_sources.get_items(datasource) == []
# a good json file
get_request().datasources_cache = {}
json_file = open(json_file_path, 'w')

View File

@ -162,6 +162,8 @@ def request_json_items(url, data_source):
else:
for item in entries.get('data'):
# skip malformed items
if not isinstance(item, dict):
continue
if item.get('id') is None or item.get('id') == '':
continue
if 'text' not in item: