datasource: fix empty jsonvalue (#76078)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2023-03-31 16:44:43 +02:00
parent f7c49be99d
commit 6d355739c7
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
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]',