Code

Opened 2 years ago

Closed 16 months ago

Last modified 15 months ago

#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

Attachments (0)

Change History (9)

comment:1 Changed 2 years ago by agriffis

  • Cc aron@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 2 years ago by jezdez

  • Cc steph added
  • Triage Stage changed from Unreviewed to Accepted

comment:3 Changed 23 months ago by steph

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!

comment:4 Changed 22 months ago by andrea

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 Changed 16 months ago by steph

I just created a test for this problem and also added the fix. See https://github.com/stephrdev/django/commit/01c1b995f09344d61949ce0171f0df04acf8f845

comment:6 Changed 16 months ago by steph

  • Owner changed from nobody to steph
  • Status changed from new to assigned

comment:7 Changed 16 months ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from assigned to closed

In 97121cb96e2f9f02f977010b5549b88f1a73610b:

Fixed #18026 -- Don't return an anonymous dict if extra_data in storage is empty.

comment:8 Changed 16 months ago by Claude Paroz <claude@…>

In fb130cb40ea9b93bae741a4f359f19819597a112:

[1.5.x] Fixed #18026 -- Don't return an anonymous dict if extra_data in storage is empty.

Backport of 97121cb9 from master.

comment:9 Changed 15 months ago by Claude Paroz <claude@…>

In fb130cb40ea9b93bae741a4f359f19819597a112:

[1.5.x] Fixed #18026 -- Don't return an anonymous dict if extra_data in storage is empty.

Backport of 97121cb9 from master.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.