Project

General

Profile

Bug #40369

import de workflow en masse : crash en cas de rôle inexistant

Added by Thomas Noël 3 months ago. Updated 3 months ago.

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

0%

Patch proposed:
No
Planning:
No

Description

Bon je n'ai pas gardé la trace, mais en cas de WorkflowImportError sur un rôle manquant dans l'import d'un export.wcs (contenant un zip d'un workflow_xml), on crashe 500... avec quand même un bout d'import des workflows qui ont réussi :/

En dehors de ne pas crasher salement, il faudrait idéalement faire une première passe "dry-run" de l'import des workflows.

History

#1 Updated by Thomas Noël 3 months ago

La trace :

Exception:
  type = '<class 'wcs.workflows.WorkflowImportError'>', value = 'Unknown referenced role (%s)'

Stack trace (most recent call first):
  File "/usr/lib/python3/dist-packages/wcs/workflows.py", line 980, in _get_role_id_from_xml
   978         # if the roles are managed by the idp, don't try further.
   979         if get_publisher() and get_cfg('sp', {}).get('idp-manage-roles') is True:
>  980             raise WorkflowImportError(N_('Unknown referenced role (%s)'), (value,))
   981
   982         # and if there's no match, create a new role

  locals:
     charset = 'utf-8'
     elem = <Element 'role_id' at 0x7fda85e1d5e8>
     include_id = True
     role = <Role 'Dechetterie_CC Portes Ile-de-France' id:76215f0c21a24dcd9f02e7e4749e88da>
     role_id = '45dd7ad8fdf443f7ac97930cf04faef9'
     self = <wcs.wf.dispatch.RuleNode object at 0x7fda923e86a0>
     value = '45dd7ad8fdf443f7ac97930cf04faef9'

  File "/usr/lib/python3/dist-packages/wcs/workflows.py", line 990, in _role_init_with_xml
   988     def _role_init_with_xml(self, attribute, elem, charset, include_id=False):
   989         setattr(self, attribute, self._get_role_id_from_xml(elem, charset,
>  990             include_id=include_id))
   991
   992

  locals:
     attribute = 'role_id'
     charset = 'utf-8'
     elem = <Element 'role_id' at 0x7fda85e1d5e8>
     include_id = True
     self = <wcs.wf.dispatch.RuleNode object at 0x7fda923e86a0>

  File "/usr/lib/python3/dist-packages/wcs/wf/dispatch.py", line 78, in role_id_init_with_xml
    76     def role_id_init_with_xml(self, elem, charset, include_id=False):
    77         self._role_init_with_xml('role_id', elem, charset,
>   78                 include_id=include_id)
    79
    80
  locals:
     charset = 'utf-8'
     elem = <Element 'role_id' at 0x7fda85e1d5e8>
     include_id = True
     self = <wcs.wf.dispatch.RuleNode object at 0x7fda923e86a0>

  File "/usr/lib/python3/dist-packages/wcs/workflows.py", line 879, in init_with_xml
   877             if getattr(self, '%s_init_with_xml' % attribute, None):
   878                 getattr(self, '%s_init_with_xml' % attribute)(el, charset,
>  879                         include_id=include_id)
   880                 continue
   881             if el is None:

  locals:
     attribute = 'role_id'
     charset = 'utf-8'
     el = <Element 'role_id' at 0x7fda85e1d5e8>
     elem = <Element 'rule' at 0x7fda85e1d1d8>
     include_id = True
     self = <wcs.wf.dispatch.RuleNode object at 0x7fda923e86a0>

  File "/usr/lib/python3/dist-packages/wcs/wf/dispatch.py", line 122, in rules_init_with_xml
   120             rule_node = RuleNode()
   121             rule_node.init_with_xml(rule_xml_node, charset,
>  122                     include_id=include_id)
   123             rules.append(rule_node.as_dict())
   124         if rules:

  locals:
     charset = 'utf-8'
     elem = <Element 'rules' at 0x7fda85e1d318>
     include_id = True
     rule_node = <wcs.wf.dispatch.RuleNode object at 0x7fda923e86a0>
     rule_xml_node = <Element 'rule' at 0x7fda85e1d1d8>
     rules = []
     self = <DispatchWorkflowStatusItem 4>

  File "/usr/lib/python3/dist-packages/wcs/workflows.py", line 879, in init_with_xml
   877             if getattr(self, '%s_init_with_xml' % attribute, None):
   878                 getattr(self, '%s_init_with_xml' % attribute)(el, charset,
>  879                         include_id=include_id)
   880                 continue
   881             if el is None:

  locals:
     attribute = 'rules'
     charset = 'utf-8'
     el = <Element 'rules' at 0x7fda85e1d318>
     elem = <Element 'item' at 0x7fda85e1d0e8>
     include_id = True
     self = <DispatchWorkflowStatusItem 4>

  File "/usr/lib/python3/dist-packages/wcs/workflows.py", line 1680, in init_with_xml
  1678             item_o = self.items[-1]
  1679             item_o.parent = self
> 1680             item_o.init_with_xml(item, charset, include_id=include_id)
  1681
  1682     def __repr__(self):

  locals:
     charset = 'utf-8'
     elem = <Element 'status' at 0x7fda923e9bd8>
     include_id = True
     item = <Element 'item' at 0x7fda85e1d0e8>
     item_o = <DispatchWorkflowStatusItem 4>
     item_type = 'dispatch'
     self = <WorkflowStatus 2 'Attribution instructeur'>
     visibility_role = <Element 'role' at 0x7fda923e99a8>

  File "/usr/lib/python3/dist-packages/wcs/workflows.py", line 622, in import_from_xml_tree
   620             status_o = WorkflowStatus()
   621             status_o.parent = workflow
>  622             status_o.init_with_xml(status, charset, include_id=include_id)
   623             workflow.possible_status.append(status_o)
   624

  locals:
     charset = 'utf-8'
     cls = <class 'wcs.workflows.Workflow'>
     include_id = True
     node = <Element 'last_modification' at 0x7fda923f29a8>
     role_node = <Element 'role' at 0x7fda923f2908>
     status = <Element 'status' at 0x7fda923e9bd8>
     status_o = <WorkflowStatus 2 'Attribution instructeur'>
     tree = <Element 'workflow' at 0x7fda923f2f98>
     workflow = <Workflow 'DGA_ASAP RECLAMATION OLD' id:9>

  File "/usr/lib/python3/dist-packages/wcs/workflows.py", line 585, in import_from_xml
   583         except:
   584             raise ValueError()
>  585         return cls.import_from_xml_tree(tree, include_id=include_id)
   586
   587     @classmethod

  locals:
     cls = <class 'wcs.workflows.Workflow'>
     fd = <zipfile.ZipExtFile name='workflows_xml/9' mode='r'>
     include_id = True
     tree = <xml.etree.ElementTree.ElementTree object at 0x7fda923efda0>

  File "/usr/lib/python3/dist-packages/wcs/publisher.py", line 227, in import_zip
   225         for f in z.namelist():
   226             if os.path.dirname(f) == 'workflows_xml' and os.path.basename(f):
>  227                 workflow = Workflow.import_from_xml(z.open(f), include_id=True)
   228                 workflow.store()
   229                 results['workflows'] += 1

  locals:
     Workflow = <class 'wcs.workflows.Workflow'>
     _decode_dict = <function WcsPublisher.import_zip.<locals>._decode_dict at 0x7fda8c0896a8>
     _decode_list = <function WcsPublisher.import_zip.<locals>._decode_list at 0x7fda8c089620>
     data = b'<datasources id="5">\n  <name>Domaines de GPSEO, pour contact</name>\n  <slug>domaines_de_gpseo_pour_contact</slug>\n
<data_source>\n    <type>json</type>\n    <value>{{passerelle_url}}csvdatasource/equipements/query/domaine/</value>\n
</data_source>\n</datasources>'
     f = 'workflows_xml/9'
     fd = <_io.BytesIO object at 0x7fda85e3bca8>
     path = '/var/lib/wcs/formulaires-gpseo.test.entrouvert.org/datasources/5'
     results = {'carddefs': 0, 'wscalls': 0, 'settings': 0, 'datasources': 4, 'roles': 0, 'formdefs': 0, 'workflows': 16, 'categories': 16}
     self = <wcs.compat.CompatWcsPublisher object at 0x7fda8c636f98>
     workflow = <Workflow 'Envoi sur fiche commune gpseo.fr' id:25>
     z = <zipfile.ZipFile file=<_io.BytesIO object at 0x7fda85e3bca8> mode='r'>

  File "/usr/lib/python3/dist-packages/wcs/admin/settings.py", line 1029, in import_submit
  1027
  1028     def import_submit(self, form):
> 1029         return get_publisher().import_zip(form.get_widget('file').parse().fp)
  1030
  1031     def sitename(self):

...

Also available in: Atom PDF