0001-datasources-check-python-dicts-all-have-id-and-text-.patch
tests/test_datasource.py | ||
---|---|---|
174 | 174 |
'[DATASOURCE] Python data source (\'[{"mairie-a-rdv", "Mairie A"}, {"mairie-b-rdv", "Mairie B"}]\') gave a non usable result' |
175 | 175 |
) |
176 | 176 | |
177 |
# list of dictionaries but some are missing a text key |
|
178 |
datasource = { |
|
179 |
'type': 'formula', |
|
180 |
'value': '[{"id": "mairie-a-rdv", "text": "Mairie A"}, {"id": "mairie-b-rdv"}]', |
|
181 |
'record_on_errors': True, |
|
182 |
} |
|
183 |
assert data_sources.get_items(datasource) == [] |
|
184 |
if pub.is_using_postgresql(): |
|
185 |
assert pub.loggederror_class.count() == 4 |
|
186 |
logged_error = pub.loggederror_class.select(order_by='id')[2] |
|
187 |
assert logged_error.workflow_id is None |
|
188 |
assert logged_error.summary == ( |
|
189 |
'[DATASOURCE] Python data source (\'[{"mairie-a-rdv", "Mairie A"}, {"mairie-b-rdv", "Mairie B"}]\') gave a non usable result' |
|
190 |
) |
|
191 | ||
177 | 192 |
if not pub.site_options.has_section('options'): |
178 | 193 |
pub.site_options.add_section('options') |
179 | 194 |
pub.site_options.set('options', 'forbid-python-expressions', 'true') |
wcs/data_sources.py | ||
---|---|---|
368 | 368 |
elif isinstance(unlazy(value[0]), str): |
369 | 369 |
return [{'id': x, 'text': x} for x in value] |
370 | 370 |
elif isinstance(value[0], dict): |
371 |
return value |
|
371 |
if all(str(x.get('id', '')) and x.get('text') for x in value): |
|
372 |
return value |
|
372 | 373 |
get_publisher().record_error( |
373 | 374 |
'Python data source (%r) gave a non usable result' % data_source.get('value'), |
374 | 375 |
context='[DATASOURCE]', |
375 |
- |