datasource: fix get_items on wrong formula (#56980)
gitea-wip/wcs/pipeline/head There was a failure building this commit
Details
gitea-wip/wcs/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
b4ee372fd1
commit
4d9e132798
|
@ -160,6 +160,20 @@ def test_python_datasource_errors(pub, error_email, http_requests, emails, caplo
|
|||
assert logged_error.workflow_id is None
|
||||
assert logged_error.summary == "[DATASOURCE] Python data source ('2') gave a non-iterable result"
|
||||
|
||||
datasource = {
|
||||
'type': 'formula',
|
||||
'value': '[{"mairie-a-rdv", "Mairie A"}, {"mairie-b-rdv", "Mairie B"}]',
|
||||
'record_on_errors': True,
|
||||
}
|
||||
assert data_sources.get_items(datasource) == []
|
||||
if pub.is_using_postgresql():
|
||||
assert pub.loggederror_class.count() == 3
|
||||
logged_error = pub.loggederror_class.select()[2]
|
||||
assert logged_error.workflow_id is None
|
||||
assert logged_error.summary == (
|
||||
'[DATASOURCE] Python data source (\'[{"mairie-a-rdv", "Mairie A"}, {"mairie-b-rdv", "Mairie B"}]\') gave a non usable result'
|
||||
)
|
||||
|
||||
|
||||
def test_python_datasource_with_evalutils(pub):
|
||||
plain_list = [
|
||||
|
|
|
@ -34,6 +34,7 @@ from .qommon.misc import get_variadic_url
|
|||
from .qommon.publisher import get_publisher_class
|
||||
from .qommon.storage import StorableObject
|
||||
from .qommon.template import Template
|
||||
from .qommon.templatetags.qommon import unlazy
|
||||
from .qommon.xml_storage import XmlStorableObject
|
||||
|
||||
data_source_functions = {}
|
||||
|
@ -328,9 +329,17 @@ def _get_structured_items(data_source, mode=None):
|
|||
elif len(value[0]) == 1:
|
||||
return [{'id': x[0], 'text': x[0]} for x in value]
|
||||
return value
|
||||
elif isinstance(value[0], str):
|
||||
elif isinstance(unlazy(value[0]), str):
|
||||
return [{'id': x, 'text': x} for x in value]
|
||||
return value
|
||||
elif isinstance(value[0], dict):
|
||||
return value
|
||||
get_publisher().record_error(
|
||||
'Python data source (%r) gave a non usable result' % data_source.get('value'),
|
||||
context='[DATASOURCE]',
|
||||
notify=data_source.get('notify_on_errors'),
|
||||
record=data_source.get('record_on_errors'),
|
||||
)
|
||||
return []
|
||||
except Exception as exc:
|
||||
get_publisher().record_error(
|
||||
'Failed to eval() Python data source (%r)' % data_source.get('value'),
|
||||
|
|
Loading…
Reference in New Issue