Projet

Général

Profil

0001-WIP-do-not-crash-on-unknown-data-source-type-36037.patch

Paul Marillonnet, 11 septembre 2019 14:52

Télécharger (2,69 ko)

Voir les différences:

Subject: [PATCH] WIP do not crash on unknown data source type (#36037)

 wcs/data_sources.py | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)
wcs/data_sources.py
117 117
def get_structured_items(data_source, mode=None):
118 118
    cache_duration = 0
119 119

  
120
    if data_source.get('type') and data_source.get('type').startswith('carddef:'):
121
        # cards
122
        from wcs.carddef import CardDef
123
        carddef = CardDef.get_by_urlname(data_source['type'][8:])
124
        items = [x.get_data_source_structured_item()
125
                 for x in carddef.data_class().select()
126
                 if not x.is_draft()]
127
        items.sort(key=lambda x: qommon.misc.simplify(x['text']))
128
        return items
129

  
130
    if data_source.get('type') not in ('json', 'jsonp', 'formula'):
131
        # named data source
132
        named_data_source = NamedDataSource.get_by_slug(data_source['type'])
133
        if named_data_source.cache_duration:
134
            cache_duration = int(named_data_source.cache_duration)
135
        data_source = named_data_source.data_source
120
    if data_source.get('type'):
121
        if data_source.get('type').startswith('carddef:'):
122
            # cards
123
            from wcs.carddef import CardDef
124
            carddef = CardDef.get_by_urlname(data_source['type'][8:])
125
            items = [x.get_data_source_structured_item()
126
                     for x in carddef.data_class().select()
127
                     if not x.is_draft()]
128
            items.sort(key=lambda x: qommon.misc.simplify(x['text']))
129
            return items
130

  
131
        if data_source.get('type') not in ('json', 'jsonp', 'formula'):
132
            # named data source
133
            named_data_source = NamedDataSource.get_by_slug(data_source['type'])
134
            if named_data_source.cache_duration:
135
                cache_duration = int(named_data_source.cache_duration)
136
            data_source = named_data_source.data_source
136 137

  
137 138
    if data_source.get('type') == 'formula':
138 139
        # the result of a python expression, it must be a list.
......
238 239
    if not data_source:
239 240
        return None
240 241
    ds_type = data_source.get('type')
242
    if not ds_type:
243
        return None
241 244
    if ds_type in ('json', 'jsonp', 'formula'):
242 245
        named_data_source = NamedDataSource()
243 246
        named_data_source.data_source = data_source
244
-