Opened 8 years ago

Closed 8 years ago

Last modified 6 years ago

#4330 closed (fixed)

formtools.preview.FormPreview unused_name uses non-instance form

Reported by: Daniel Blasco <daniel@…> Owned by: adrian
Component: contrib.formtools Version: master
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hi there,
The FormPreview on the unused_name function uses self.form.fields from the form class, but form.fields isn't available on the Class but on the instance of a form so FormPreview raises an AttributeError when it's instances are called:

Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py" in get_response
  77. response = callback(request, *callback_args, **callback_kwargs)
File "/usr/lib/python2.4/site-packages/django/contrib/formtools/preview.py" in __call__
  68. stage = {'1': 'preview', '2': 'post'}.get(request.POST.get(self.unused_name('stage')), 'preview')
File "/usr/lib/python2.4/site-packages/django/contrib/formtools/preview.py" in unused_name
  86. f = self.form.fields[name]

  AttributeError at /ab/add/post/
  type object 'CuentaNewForm' has no attribute 'fields'

Maybe it should read form.base_fields from the class or instantiate a form to read .fields

Attachments (1)

4330.diff (513 bytes) - added by Daniel Blasco <daniel@…> 8 years ago.
Patch to use base_fields instead of fields.

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by Daniel Blasco <daniel@…>

Patch to use base_fields instead of fields.

comment:1 Changed 8 years ago by anonymous

  • Has patch set
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by Marc Fargas <telenieko@…>

  • Triage Stage changed from Unreviewed to Ready for checkin

This is broken since [4437] (January) some regression test should have spotted this but that was not the case ;(
Anyway, the attached patch solves a broken thing so I'm marking it Ready for Check-in, for the test problem I'd better file a new ticket so we can get this solved ASAP.

triagers: feel free to move back to Accepted and +needs_test if you feel we should get the test within the patch at once ;)

comment:3 Changed 8 years ago by mtredinnick

The test can wait, Mark, only because we need some infrastructure work so that tests for contrib/ apps can live under their app, rather than in the main test dir. That discussion is happening on django-dev right now.

comment:4 follow-up: Changed 8 years ago by mtredinnick

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

(In [5293]) Fixed #4330 -- Fixed typo when retrieving field names. Patch from Marc Fargas.

comment:5 in reply to: ↑ 4 Changed 8 years ago by Marc Fargas <telenieko@…>

Replying to mtredinnick:

(In [5293]) Fixed #4330 -- Fixed typo when retrieving field names. Patch from Marc Fargas.

Thanks, but the patch came from Daniel ;)

comment:6 Changed 8 years ago by mtredinnick

Oh, sorry about that, Daniel.

Guess you owe us one patch, then, Marc. :-)

comment:7 Changed 8 years ago by Marc Fargas <telenieko@…>

Uhm.. I'll have to take a look at Reports then... ;)

Note: See TracTickets for help on using tickets.
Back to Top