Projet

Général

Profil

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

Lauréline Guérin, 30 septembre 2021 09:30

Télécharger (2,89 ko)

Voir les différences:

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

 tests/test_datasource.py | 14 ++++++++++++++
 wcs/data_sources.py      | 13 +++++++++++--
 2 files changed, 25 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
34 34
from .qommon.publisher import get_publisher_class
35 35
from .qommon.storage import StorableObject
36 36
from .qommon.template import Template
37
from .qommon.templatetags.qommon import unlazy
37 38
from .qommon.xml_storage import XmlStorableObject
38 39

  
39 40
data_source_functions = {}
......
328 329
                elif len(value[0]) == 1:
329 330
                    return [{'id': x[0], 'text': x[0]} for x in value]
330 331
                return value
331
            elif isinstance(value[0], str):
332
            elif isinstance(unlazy(value[0]), str):
332 333
                return [{'id': x, 'text': x} for x in value]
333
            return value
334
            elif isinstance(value[0], dict):
335
                return value
336
            get_publisher().record_error(
337
                'Python data source (%r) gave a non usable result' % data_source.get('value'),
338
                context='[DATASOURCE]',
339
                notify=data_source.get('notify_on_errors'),
340
                record=data_source.get('record_on_errors'),
341
            )
342
            return []
334 343
        except Exception as exc:
335 344
            get_publisher().record_error(
336 345
                'Failed to eval() Python data source (%r)' % data_source.get('value'),
337
-