#16393: CookieWizard incompatible with simlejson 2.0.9
------------------------------------+------------------------
               Reporter:  kmtracey  |          Owner:  nobody
                   Type:  Bug       |         Status:  new
              Milestone:            |      Component:  Forms
                Version:  SVN       |       Severity:  Normal
             Resolution:            |       Keywords:
           Triage Stage:  Accepted  |      Has patch:  0
    Needs documentation:  0         |    Needs tests:  0
Patch needs improvement:  0         |  Easy pickings:  0
                  UI/UX:  0         |
------------------------------------+------------------------

Comment (by jezdez):

 Replying to [comment:3 kmtracey]:
 > This is pdb info from a session where simplejson 2.0.9 was installed. I
 added breakpoints to the django/contrib/formtools/wizard/storage/cookie.py
 file, methods load_data and update_response to see what was getting stored
 in the cookie and what was subsequently loaded:
 >
 > {{{
 > --> ./runtests.py --settings=testdb.sqlite -v0
 formtools.CookieWizardTests.test_cleaned_data
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(32)update_response()
 > -> response.set_signed_cookie(self.prefix,
 self.encoder.encode(self.data))
 > (Pdb) self.data
 > {'step_files': {}, 'step': u'form1', 'extra_data': {}, 'step_data': {}}
 > (Pdb) c
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(27)load_data()
 > -> return json.loads(data, cls=json.JSONDecoder)
 > (Pdb) n
 > --Return--
 > > /home/kmtracey/django/hg-
 
django/django/contrib/formtools/wizard/storage/cookie.py(27)load_data()->{u'extra_data':
 {}, u'step': u'form1', u'step_data': {}, u'step_files': {}}
 > -> return json.loads(data, cls=json.JSONDecoder)
 >
 > # No problem above, first calls to store/load the cookie data have no
 data that causes a problem
 >
 > # Next iteration is where there's a problem. The step_data for form1 is
 a QueryDict
 >
 > (Pdb) c
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(32)update_response()
 > -> response.set_signed_cookie(self.prefix,
 self.encoder.encode(self.data))
 > (Pdb) self.data
 > {u'step_files': {u'form1': {}}, u'step': u'form2', u'extra_data': {},
 u'step_data': {u'form1': <QueryDict: {u'form1-name': [u'Pony'], u
 'cookie_contact_wizard-current_step': [u'form1'], u'form1-user': [u'1'],
 u'form1-thirsty': [u'2']}>}}
 > (Pdb) self.data['step_data']['form1']
 > <QueryDict: {u'form1-name': [u'Pony'], u'cookie_contact_wizard-
 current_step': [u'form1'], u'form1-user': [u'1'], u'form1-thirsty':
 [u'2']}>
 > (Pdb) c
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(27)load_data()
 > -> return json.loads(data, cls=json.JSONDecoder)
 > (Pdb) n
 > --Return--
 > > /home/kmtracey/django/hg-
 
django/django/contrib/formtools/wizard/storage/cookie.py(27)load_data()->{u'extra_data':
 {}, u'step': u'form2', u'step_data': {u'form1': {u'cookie...ent_step':
 [u'form1'], u'form1-name': [u'Pony'], u'form1-thirsty': [u'2'],
 u'form1-user': [u'1']}}, u'step_files': {u'form1': {}}}
 > -> return json.loads(data, cls=json.JSONDecoder)
 > (Pdb) n
 >
 > # When step_data for form1 is re-constituted, the values for all the
 keys are wrapped in lists
 > # This ultimately triggers errors like: TypeError: int() argument must
 be a string or a number, not 'list'
 > # when the wizard code uses the re-constituted step data as data for the
 form.
 >
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(14)__init__()
 > -> if self.data is None:
 > (Pdb) self.data['step_data']['form1']
 > {u'form1-user': [u'1'], u'cookie_contact_wizard-current_step':
 [u'form1'], u'form1-name': [u'Pony'], u'form1-thirsty': [u'2']}
 > (Pdb)
 > }}}
 >
 > This is with simplejson 2.1.6 installed:
 >
 > {{{
 > --> ./runtests.py --settings=testdb.sqlite -v0
 formtools.CookieWizardTests.test_cleaned_data
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(32)update_response()
 > -> response.set_signed_cookie(self.prefix,
 self.encoder.encode(self.data))
 > (Pdb) c
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(27)load_data()
 > -> return json.loads(data, cls=json.JSONDecoder)
 > (Pdb) c
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(32)update_response()
 > -> response.set_signed_cookie(self.prefix,
 self.encoder.encode(self.data))
 > (Pdb) self.data
 > {u'step_files': {u'form1': {}}, u'step': u'form2', u'extra_data': {},
 u'step_data': {u'form1': <QueryDict: {u'form1-name': [u'Pony'], u
 'cookie_contact_wizard-current_step': [u'form1'], u'form1-user': [u'1'],
 u'form1-thirsty': [u'2']}>}}
 > (Pdb) self.data['step_data']['form1']
 > <QueryDict: {u'form1-name': [u'Pony'], u'cookie_contact_wizard-
 current_step': [u'form1'], u'form1-user': [u'1'], u'form1-thirsty':
 [u'2']}>
 > (Pdb) c
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(27)load_data()
 > -> return json.loads(data, cls=json.JSONDecoder)
 > (Pdb) n
 > --Return--
 > > /home/kmtracey/django/hg-
 
django/django/contrib/formtools/wizard/storage/cookie.py(27)load_data()->{u'extra_data':
 {}, u'step': u'form2', u'step_data': {u'form1': {u'cookie...ent_step':
 u'form1', u'form1-name': u'Pony', u'form1-thirsty': u'2', u'form1-user':
 u'1'}}, u'step_files': {u'form1': {}}}
 > -> return json.loads(data, cls=json.JSONDecoder)
 > (Pdb) n
 >
 >
 > # With this level of simplejson, the step_data for form1 does not have
 its values wrapped in lists
 >
 > > /home/kmtracey/django/hg-
 django/django/contrib/formtools/wizard/storage/cookie.py(14)__init__()
 > -> if self.data is None:
 > (Pdb) self.data['step_data']['form1']
 > {u'form1-user': u'1', u'cookie_contact_wizard-current_step': u'form1',
 u'form1-name': u'Pony', u'form1-thirsty': u'2'}
 > (Pdb)
 > }}}
 >
 > Thinking about it a bit more, I do kind of wonder whether the formwizard
 will correctly handle forms where multi-value keys are expected, since
 round-tripping through serialization you don't get the !QueryDict with its
 special characteristics back, and the formwizard code seems to be using
 the de-serialized version for cleaning on the last step...

 Huh, that is indeed a good question which I have to pass along to Stephan
 who wrote the new wizard initially..

-- 
Ticket URL: <https://code.djangoproject.com/ticket/16393#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to