Bug #67862
KeyError "form_user" sur appel à l'API /@schema, avec une source de données filtrée sur l'usager
Début:
02 août 2022
Echéance:
% réalisé:
0%
Temps estimé:
Patch proposed:
Oui
Planning:
Non
Description
File "/usr/lib/python3/dist-packages/wcs/carddef.py", line 207, in get_data_source_items 205 if not get_by_id: 206 variables = get_publisher().substitutions.get_context_variables(mode='lazy') > 207 user = variables['form_user'] 208 criterias.append(Equal('user_id', str(user.id) if user else '-1')) 209 else: locals: carddef = <CardDef 'DJS - Membre TEAM13' id:28> cls = <class 'wcs.carddef.CardDef'> criterias = [<StrictNotEqual (attribute: 'status', value: 'draft')>, <Null (attribute: 'anonymised')>] custom_view = None data_source_id = 'carddef:djs-membre-team13:_with_user_filter' … File "/usr/lib/python3/dist-packages/wcs/data_sources.py", line 330, in get_structured_items 328 329 def get_structured_items(data_source, mode=None, include_disabled=True, raise_on_error=False): > 330 items = _get_structured_items(data_source, mode=mode, raise_on_error=raise_on_error) 331 if not include_disabled: 332 items = [i for i in items if not i.get('disabled')] locals: data_source = {'type': 'carddef:djs-membre-team13:_with_user_filter'} include_disabled = True mode = None raise_on_error = False File "/usr/lib/python3/dist-packages/wcs/fields.py", line 2442, in export_to_json 2440 field = super().export_to_json(include_id=include_id) 2441 if self.data_source: > 2442 structured_items = data_sources.get_structured_items(self.data_source) 2443 if structured_items: 2444 field['structured_items'] = structured_items … PATH_INFO '/api/cards/djs-participation-team13/@schema'
Fichiers
Révisions associées
Historique
Mis à jour par Frédéric Péters il y a presque 2 ans
- Fichier 0001-api-do-not-return-any-options-in-schema-for-sources-.patch 0001-api-do-not-return-any-options-in-schema-for-sources-.patch ajouté
- Statut changé de Nouveau à Solution proposée
- Patch proposed changé de Non à Oui
Mis à jour par Thomas Noël il y a presque 2 ans
- Statut changé de Solution proposée à Solution validée
Ok.
Mais sur le côté, je me demande quand même tout à coup pourquoi on fait
criterias.append(Equal('user_id', str(user.id) if user else '-1'))
au lieu de faire plus rapidement :
if not user: return [] criterias.append(Equal('user_id', str(user.id)))
Discuté avec Frédéric : « il y a peut-être un intérêt à ne pas courtcircuiter tout de suite. »
J'en ai fait un ticket à part #67884
Mis à jour par Frédéric Péters il y a presque 2 ans
- Statut changé de Solution validée à Résolu (à déployer)
commit 3bcf1f3e2a6ab7619556bfd98df605d53e3d44e3 Author: Frédéric Péters <fpeters@entrouvert.com> Date: Tue Aug 2 14:49:45 2022 +0200 api: do not return any options in schema for sources linked to user (#67862)
Mis à jour par Transition automatique il y a presque 2 ans
- Statut changé de Résolu (à déployer) à Solution déployée
api: do not return any options in schema for sources linked to user (#67862)