datasource: fix empty jsonvalue (#76078) #217

Merged
lguerin merged 1 commits from wip/76078-fix-json-datasource into main 2023-03-31 17:11:33 +02:00
2 changed files with 9 additions and 1 deletions

View File

@ -359,6 +359,14 @@ def test_jsonvalue_datasource_errors(pub):
== "[DATASOURCE] JSON data source ('[{\"id\": \"1\", \"text\": \"foo\"}, {\"id\": \"2\", \"text\": \"\"}]') gave a non usable result"
)
pub.loggederror_class.wipe()
# value not configured
datasource = {'type': 'jsonvalue', 'record_on_errors': True}
assert data_sources.get_items(datasource) == []
assert pub.loggederror_class.count() == 1
logged_error = pub.loggederror_class.select()[0]
assert logged_error.summary == "[DATASOURCE] JSON data source (None) gave a non usable result"
def test_json_datasource(pub, requests_pub):
get_request().datasources_cache = {}

View File

@ -415,7 +415,7 @@ def _get_structured_items(data_source, mode=None, raise_on_error=False):
if data_source.get('type') == 'jsonvalue':
try:
value = json.loads(data_source.get('value'))
except json.JSONDecodeError:
except (json.JSONDecodeError, TypeError):
get_publisher().record_error(
'JSON data source (%r) gave a non usable result' % data_source.get('value'),
context='[DATASOURCE]',