Project

General

Profile

Bug #41054

Trace si une source de données json renvoie une erreure http

Added by Thomas Noël 15 days ago. Updated 15 days ago.

Status:
Nouveau
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
26 Mar 2020
Due date:
% Done:

0%

Patch proposed:
No
Planning:
No

Description

Une source de données qui renvoie une erreur (400 ou 500) va provoquer une 500 lors de l'affichage du formulaire :

Exception:
  type = '<class 'wcs.qommon.errors.ConnectionError'>', value = 'error in HTTP request to (status: 400)'

Stack trace (most recent call first):
  File "/usr/lib/python3/dist-packages/wcs/qommon/misc.py", line 341, in _http_request
   339 
   340     if raise_on_http_errors and not (200 <= status < 300):
>  341         raise ConnectionError('error in HTTP request to (status: %s)' % status)
   342 
   343     return response, status, data, auth_header

  locals: 
     adapter = <requests.adapters.HTTPAdapter object at 0x7f9b5893deb8>
     auth_header = None
     body = None
     cert_file = None
     data = b'{"err_class": "passerelle.views.WrongParameter", "err_desc": "extra parameters: u\'id\'.", "data": null, "err": 1}'
     headers = {}
     hostname = '...'
     method = 'GET'
     raise_on_http_errors = True
     response = <Response [400]>
     session = <requests.sessions.Session object at 0x7f9b589a7978>
     status = 400
     timeout = 28
     url = '...'

  File "/usr/lib/python3/dist-packages/wcs/qommon/misc.py", line 350, in urlopen
   348             url, 'GET' if data is None else 'POST',
   349             body=data,
>  350             raise_on_http_errors=True)
   351     return BytesIO(data)
   352 

  locals: 
     data = None
     url = '...'

  File "/usr/lib/python3/dist-packages/wcs/data_sources.py", line 377, in load_json
   375         unsigned_url = url
   376         url = sign_url_auto_orig(url)
>  377         resp = misc.urlopen(url).read()
   378         if hasattr(request, 'datasources_cache'):
   379             request.datasources_cache[unsigned_url] = resp

  locals: 
     param_name = 'id'
     param_value = '423080'
     request = <wcs.compat.CompatHTTPRequest object at 0x7f9b589e84e0>
     self = <NamedDataSource '...' id:72>
     unsigned_url = 'https://passerelle...'
     url = '...'
     vars = {...}

  File "/usr/lib/python3/dist-packages/wcs/data_sources.py", line 391, in get_structured_value
   389         value = None
   390         if self.type == 'json' and self.id_parameter:
>  391             resp = self.load_json(self.id_parameter, option_id)
   392             response = misc.json_loads(resp)
   393             if response['data']:

  locals: 
     option_id = '423080'
     self = <NamedDataSource '...' id:72>
     value = None

  File "/usr/lib/python3/dist-packages/wcs/data_sources.py", line 383, in get_display_value
   381 
   382     def get_display_value(self, option_id):
>  383         value = self.get_structured_value(option_id)
   384         if value:
   385             return value.get('text')

  locals: 
     option_id = '423080'
     self = <NamedDataSource '...' id:72>

  File "/usr/lib/python3/dist-packages/wcs/fields.py", line 1482, in get_display_value
  1480                             '%s_%s' % (data_source.get_jsonp_url(), value))
  1481 
> 1482         return data_source.get_display_value(value)
  1483 
  1484     def get_view_value(self, value, value_id=None):

  locals: 
     data_source = <NamedDataSource '...' id:72>
     self = <ItemField 5 'Enfant'>
     value = '423080'

  File "/usr/lib/python3/dist-packages/wcs/fields.py", line 1543, in store_display_value
  1541                             '%s_%s' % (real_data_source.get('value'), value)] = display_value
  1542                 return display_value
> 1543         return self.get_display_value(value)
  1544 
  1545     def store_structured_value(self, data, field_id):

  locals: 
     data = {'5': '423080'}
     data_source = <NamedDataSource '...' id:72>
     field_id = '5'
     self = <ItemField 5 'Enfant'>
     value = '423080'

  File "/usr/lib/python3/dist-packages/wcs/formdef.py", line 714, in get_field_data
   712             d[field.id] = field.convert_value_from_str(d[field.id])
   713         if d.get(field.id) is not None and field.store_display_value:
>  714             display_value = field.store_display_value(d, field.id)
   715             if display_value is not None:
   716                 d['%s_display' % field.id] = display_value

  locals: 
     d = {'5': '423080'}
     field = <ItemField 5 'Enfant'>
     self = <FormDef '...' id:226>
     widget = <RadiobuttonsWidget at 7f9b589385c0: f5>

  File "/usr/lib/python3/dist-packages/wcs/formdef.py", line 594, in add_fields_to_form
   592             widget.field = field
   593             if transient_formdata and not widget.is_hidden:
>  594                 transient_formdata.data.update(self.get_field_data(field, widget))
   595                 # invalidate cache as comment fields (and other things?) may
   596                 # have accessed variables in non-lazy mode and caused a cache

  locals: 
     current_page = 0
     displayed_fields = [<CommentField 14 '<p>{{webservice.axel_dates_de_gestion}}</p>'>, <CommentField 1 '<p>{{form_user_name_identifier_0}}</p>'>, <CommentField 2 '<p>Code mise &agrave; jour {{webservice.family_info.data.CODEMIS'>, <CommentField 3 '<p><br />\n{% if today|date:"m" in form_option_liste_des_mois_pou'>, <CommentField 15 "<p>Seuls les enfants inscrits à une activité pour l'année en cou">, <ItemField 5 'Enfant'>]
     field = <ItemField 5 'Enfant'>
     form = <wcs.qommon.form.Form object at 0x7f9b5893b940>
     form_data = None
     on_page = True
     page = <PageField 4 "Choix de l'enfant">
     self = <FormDef 'Réservation annuelle à la restauration scolaire et aux activités périscolaires (non testable)' id:226>
     transient_formdata = <FormData 'Réservation annuelle à la restauration scolaire et aux activités périscolaires (non testable) - n°None' id:None>
     value = None
     visible = True
     widget = <RadiobuttonsWidget at 7f9b589385c0: f5>

  File "/usr/lib/python3/dist-packages/wcs/formdef.py", line 559, in create_form
   557                 page=page,
   558                 displayed_fields=displayed_fields,
>  559                 transient_formdata=transient_formdata)
   560         return form
   561 

  locals: 
     displayed_fields = [<CommentField 14 '<p>{{webservice.axel_dates_de_gestion}}</p>'>, <CommentField 1 '<p>{{form_user_name_identifier_0}}</p>'>, <CommentField 2 '<p>Code mise &agrave; jour {{webservice.family_info.data.CODEMIS'>, <CommentField 3 '<p><br />\n{% if today|date:"m" in form_option_liste_des_mois_pou'>, <CommentField 15 "<p>Seuls les enfants inscrits à une activité pour l'année en cou">, <ItemField 5 'Enfant'>]
     form = <wcs.qommon.form.Form object at 0x7f9b5893b940>
     page = <PageField 4 "Choix de l'enfant">
     self = <FormDef 'Réservation annuelle à la restauration scolaire et aux activités périscolaires (non testable)' id:226>
     transient_formdata = <FormData 'Réservation annuelle à la restauration scolaire et aux activités périscolaires (non testable) - n°None' id:None>

  File "/usr/lib/python3/dist-packages/wcs/forms/root.py", line 560, in create_form
   558 
   559     def create_form(self, *args, **kwargs):
>  560         form = self.formdef.create_form(*args, **kwargs)
   561         form.attrs['data-live-url'] = self.formdef.get_url() + 'live'
   562         return form

  locals: 
     args = ()
     kwargs = {'displayed_fields': [<CommentField 14 '<p>{{webservice.axel_dates_de_gestion}}</p>'>, <CommentField 1 '<p>{{form_user_name_identifier_0}}</p>'>, <CommentField 2 '<p>Code mise &agrave; jour {{webservice.family_info.data.CODEMIS'>, <CommentField 3 '<p><br />\n{% if today|date:"m" in form_option_liste_des_mois_pou'>, <CommentField 15 "<p>Seuls les enfants inscrits à une activité pour l'année en cou">, <ItemField 5 'Enfant'>], 'page': <PageField 4 "Choix de l'enfant">, 'transient_formdata': <FormData 'Réservation annuelle à la restauration scolaire et aux activités périscolaires (non testable) - n°None' id:None>}
     self = <modules.formpage.AlternateFormPage object at 0x7f9b5893d978>

  File "/usr/lib/python3/dist-packages/wcs/forms/root.py", line 782, in _q_index
   780                 form = self.create_form(page=page,
   781                         displayed_fields=submitted_fields,
>  782                         transient_formdata=transient_formdata)
   783             form.add_submit('previous')
   784             if self.has_draft_support():

  locals: 
     authentication_context_check_result = None
     existing_formdata = None
     form = <wcs.qommon.form.Form object at 0x7f9b5893f320>
     magictoken = 'yZsBe5hJZ2E'
     no_magic = <object object at 0x7f9b656c5450>
     page = <PageField 4 "Choix de l'enfant">
     page_no = 0
     self = <modules.formpage.AlternateFormPage object at 0x7f9b5893d978>
     session = <Session at 7f9b58a5b198: Syf5bT9vvgNK22MGrIpSHg>
     session_magic_token = <object object at 0x7f9b656c5450>
     step = 0
     submitted_fields = [<CommentField 14 '<p>{{webservice.axel_dates_de_gestion}}</p>'>, <CommentField 1 '<p>{{form_user_name_identifier_0}}</p>'>, <CommentField 2 '<p>Code mise &agrave; jour {{webservice.family_info.data.CODEMIS'>, <CommentField 3 '<p><br />\n{% if today|date:"m" in form_option_liste_des_mois_pou'>, <CommentField 15 "<p>Seuls les enfants inscrits à une activité pour l'année en cou">, <ItemField 5 'Enfant'>]
     transient_formdata = <FormData 'Réservation annuelle à la restauration scolaire et aux activités périscolaires (non testable) - n°None' id:None>

...

History

#2 Updated by Thomas Noël 15 days ago

A l'origine sur #41040 le problème vient d'une source de donnée mal configurée, avec un "id_parameter" alors que le webservice ne le supporte pas (et donc répond 400).

Mais dans un cas plus général, si une source de données tombe en panne ou est indispo, on devrait voir comment ne pas crasher... je pense ?

#3 Updated by Benjamin Dauvergne 15 days ago

Ne pas tracer, mais de fait le système est indisponible si ça arrive, il faut quand même le dire à l'usager.

Also available in: Atom PDF