Opened 18 years ago

Closed 18 years ago

#3278 closed defect (fixed)

newforms class names get overwritten

Reported by: russblau@… Owned by: Adrian Holovaty
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: no UI/UX: no

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!)

Change History (3)

comment:1 by russblau@…, 18 years ago

Resolution: duplicate
Status: newclosed

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 by anonymous, 18 years ago

Resolution: duplicate
Status: closedreopened

comment:3 by Adrian Holovaty, 18 years ago

Resolution: fixed
Status: reopenedclosed

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

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