Project

General

Profile

Bug #13777

modification des champs de traitement: crash sur fichier uploadé

Added by Thomas Noël almost 6 years ago. Updated almost 6 years ago.

Status:
Fermé
Priority:
Normal
Assignee:
Target version:
Start date:
27 October 2016
Due date:
% Done:

0%

Estimated time:
Patch proposed:
Yes
Planning:

Description

Contexte:
  • un formulaire de workflow (visite) avec un champs fichier (photo1)
  • puis une action "modification des champs de traitement" qui utilise =visite_var_photo1_raw

Mais ça ne marche pas, le champs de traitement reste vide.

La trace pourtant fait mention d'un objet "<PicklableUpload at 793d878: facture-elec.png>" :

Exception:
  type = '<type 'exceptions.ValueError'>', value = 'invalid data for file type (<PicklableUpload at 793d878: facture-elec.png>)'

Stack trace (most recent call first):
  File "/usr/lib/python2.7/dist-packages/wcs/wf/backoffice_fields.py", line 108, in get_file_value
   106                 return upload
   107
>  108         raise ValueError('invalid data for file type (%r)' % new_value)
   109
   110     def perform(self, formdata):

  locals:
     new_value = <PicklableUpload at 793d878: facture-elec.png>
     self = <wcs.wf.backoffice_fields.SetBackofficeFieldsWorkflowStatusItem object at 0x62e3250>

  File "/usr/lib/python2.7/dist-packages/wcs/wf/backoffice_fields.py", line 130, in perform
   128                     new_value = self.get_file_value(new_value)
   129             except ValueError:
>  130                 get_publisher().notify_of_exception(sys.exc_info())
   131                 continue
   132

  locals:
     self = <wcs.wf.backoffice_fields.SetBackofficeFieldsWorkflowStatusItem object at 0x62e3250>
     field = {'field_id': 'bo16', 'value': '=visite_var_photo1_raw'}
     x = <wcs.fields.TextField object at 0x7b91710>
     new_value = <PicklableUpload at 793d878: facture-elec.png>
     formdef_field = <wcs.fields.FileField object at 0x7b91150>
     formdata = <Demande-De-Proximite 'Demande de proximit\xc3\xa9 - n\xc2\xb01-15' id:15>

Pourtant dans le code :

    def get_file_value(self, new_value):
        if isinstance(new_value, PicklableUpload):
            return new_value
        ...
        raise ValueError('invalid data for file type (%r)' % new_value)

donc le isinstance ne passe pas... peut-être confusion entre qommon.form.PicklableUpload et wcs.qommon.form.PicklableUpload ? (souvenir d'un pb passé, #11000)


Files

Associated revisions

Revision 7e91ff8e (diff)
Added by Thomas Noël almost 6 years ago

workflows: check file type with hasattr() for backoffice fields (#13777)

PicklableUpload may exist in different namespaces, and then there's also
an independant UploadedFile class; just check if will duck like a file.
Similar to #11000 (commit 2adbdc1720)

History

#1

Updated by Thomas Noël almost 6 years ago

Ca crache effectivement quand

--- a/tests/test_workflows.py
+++ b/tests/test_workflows.py
@@ -1922,7 +1922,8 @@ def test_set_backoffice_field_file(pub):
     formdef.workflow_id = wf.id
     formdef.store()

-    upload = PicklableUpload('test.jpeg', 'image/jpeg')
+    from wcs.qommon.form import PicklableUpload as PicklableUpload2
+    upload = PicklableUpload2('test.jpeg', 'image/jpeg')
     upload.receive([open(os.path.join(os.path.dirname(__file__), 'image-with-gps-data.jpeg')).read()])

     formdata = formdef.data_class()()

#2

Updated by Thomas Noël almost 6 years ago

Bon, j'ai pas testé "en vrai", cependant.

#3

Updated by Thomas Noël almost 6 years ago

Testé sur la recette, et c'était bien le soucis. Relecteurs bienvenus.

#4

Updated by Frédéric Péters (de retour le 10/10) almost 6 years ago

/Same as/Similar to/.

Je virerais le isinstance().

#7

Updated by Thomas Noël almost 6 years ago

  • Status changed from En cours to Résolu (à déployer)
commit 7e91ff8ee98ac23aad8f91ece3bf9b35cc55ac63
Author: Thomas NOEL <tnoel@entrouvert.com>
Date:   Thu Oct 27 16:55:53 2016 +0200

    workflows: check file type with hasattr() for backoffice fields (#13777)

    PicklableUpload may exist in different namespaces, and then there's also
    an independant UploadedFile class; just check if will duck like a file.
    Similar to #11000 (commit 2adbdc1720)

#8

Updated by Frédéric Péters (de retour le 10/10) almost 6 years ago

  • Target version set to v1.63
#9

Updated by Frédéric Péters (de retour le 10/10) almost 6 years ago

  • Status changed from Résolu (à déployer) to Fermé

Also available in: Atom PDF