Code

Opened 8 years ago

Closed 8 years ago

#3278 closed defect (fixed)

newforms class names get overwritten

Reported by: russblau@… Owned by: adrian
Component: Forms Version:
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

In root/django/trunk/django/newforms/forms.py, the definition of DeclarativeFieldsMetaclass inadvertently overwrites the Forms class's name:

29 class DeclarativeFieldsMetaclass(type):
30 "Metaclass that converts Field attributes to a dictionary called 'fields'."
31 def new(cls, name, bases, attrs):
32 fields = [(name, attrs.pop(name)) for name, obj in attrs.items() if isinstance(obj, Field)]
33 fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
34 attrsfields? = SortedDictFromList(fields)
35 return type.new(cls, name, bases, attrs)

Fix: In line 32 [only], change "name" to anything else! (Note that "name" is also one of the method arguments!)

Attachments (0)

Change History (3)

comment:1 Changed 8 years ago by russblau@…

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

Sorry for the mess in original comment -- the code fragment should be as follows:

29 class DeclarativeFieldsMetaclass(type): 
30     "Metaclass that converts Field attributes to a dictionary called 'fields'."
31     def new(cls, name, bases, attrs): 
32         fields = [(name, attrs.pop(name)) for name, obj in attrs.items() if isinstance(obj, Field)] 
33         fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter)) 
34         attrsfields = SortedDictFromList(fields) 
35         return type.new(cls, name, bases, attrs) 

comment:2 Changed 8 years ago by anonymous

  • Resolution duplicate deleted
  • Status changed from closed to reopened

comment:3 Changed 8 years ago by adrian

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

(In [4303]) Fixed #3278 -- newforms: Fixed bug in DeclarativeFieldsMetaclass where it inadvertently overrode the class' name. Thanks, russblau@…

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.