Projet

Général

Profil

0001-datasource-fix-get_items-on-wrong-formula-56980.patch

Lauréline Guérin, 20 septembre 2021 09:31

Télécharger (3,02 ko)

Voir les différences:

Subject: [PATCH] datasource: fix get_items on wrong formula (#56980)

 tests/test_datasource.py | 14 ++++++++++++++
 wcs/data_sources.py      | 14 ++++++++++++--
 2 files changed, 26 insertions(+), 2 deletions(-)
tests/test_datasource.py
160 160
        assert logged_error.workflow_id is None
161 161
        assert logged_error.summary == "[DATASOURCE] Python data source ('2') gave a non-iterable result"
162 162

  
163
    datasource = {
164
        'type': 'formula',
165
        'value': '[{"mairie-a-rdv", "Mairie A"}, {"mairie-b-rdv", "Mairie B"}]',
166
        'record_on_errors': True,
167
    }
168
    assert data_sources.get_items(datasource) == []
169
    if pub.is_using_postgresql():
170
        assert pub.loggederror_class.count() == 3
171
        logged_error = pub.loggederror_class.select()[2]
172
        assert logged_error.workflow_id is None
173
        assert logged_error.summary == (
174
            '[DATASOURCE] Python data source (\'[{"mairie-a-rdv", "Mairie A"}, {"mairie-b-rdv", "Mairie B"}]\') gave a non usable result'
175
        )
176

  
163 177

  
164 178
def test_python_datasource_with_evalutils(pub):
165 179
    plain_list = [
wcs/data_sources.py
298 298
        #   - three elements, (id, text, key)
299 299
        #   - two elements, (id, text)
300 300
        #   - a single element, (id,)
301
        from .variables import LazyFieldVar
302

  
301 303
        variables = get_publisher().substitutions.get_context_variables(mode=mode)
302 304
        global_eval_dict = get_publisher().get_global_eval_dict()
303 305
        global_eval_dict.update(data_source_functions)
......
323 325
                elif len(value[0]) == 1:
324 326
                    return [{'id': x[0], 'text': x[0]} for x in value]
325 327
                return value
326
            elif isinstance(value[0], str):
328
            elif isinstance(value[0], (str, LazyFieldVar)):
327 329
                return [{'id': x, 'text': x} for x in value]
328
            return value
330
            elif isinstance(value[0], dict):
331
                return value
332
            get_publisher().record_error(
333
                'Python data source (%r) gave a non usable result' % data_source.get('value'),
334
                context='[DATASOURCE]',
335
                notify=data_source.get('notify_on_errors'),
336
                record=data_source.get('record_on_errors'),
337
            )
338
            return []
329 339
        except Exception as exc:
330 340
            get_publisher().record_error(
331 341
                'Failed to eval() Python data source (%r)' % data_source.get('value'),
332
-