#18026 closed Bug (fixed)
can't update extra_data in process_step of form wizard
Reported by: | creecode | Owned by: | steph |
---|---|---|---|
Component: | contrib.formtools | Version: | 1.4 |
Severity: | Normal | Keywords: | form wizard extra_data process_step can't update |
Cc: | aron@…, steph | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
The WizardView.process_step documentation indicates that it is possible to set storage extra data but this appears not to be the case.
It seems the problem lies with the getter for extra_data when it finds an empty dict for extra_data it returns an anonymous dict instead of self.data[self.extra_data_key].
This is a one line change at https://code.djangoproject.com/browser/django/trunk/django/contrib/formtools/wizard/storage/base.py#L40 or there abouts.
def _get_extra_data(self):
return self.data[self.extra_data_key] or {}
...changes to...
def _get_extra_data(self):
return self.data[self.extra_data_key]
Credit to Ryan Show who identified the problem. I just wanted to get it into the tracker here as I've run into the problem myself.
Toodle-looooooooo........
creecode
Change History (9)
comment:1 by , 13 years ago
Cc: | added |
---|
comment:2 by , 13 years ago
Cc: | added |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 13 years ago
comment:4 by , 12 years ago
I suppose that the intended use of the extra_data property was as single value, not as dictionary.
What I mean is that you can do:
mywizard.storage.extra_data = {'foo' : 'bar'}
but not
mywizard.storage.extra_data['foo'] = 'bar'
Note that extra_data_key is a constant (extra_data_key = 'extra_data') in the BaseStorage class.
I think that if the intended use has to be changed, maybe a design decision is needed.
comment:5 by , 12 years ago
I just created a test for this problem and also added the fix. See https://github.com/stephrdev/django/commit/01c1b995f09344d61949ce0171f0df04acf8f845
comment:6 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Could you add a test for this issue? I think a setdefault instead of the anonymous dict before returning the extra data key would help. Maybe you could add a patch for this too - would be really cool!