Opened 9 years ago

Closed 9 years ago

#7342 closed (fixed)

Using a new-style class for Meta raises an exception

Reported by: Marty Alchin Owned by: Marty Alchin
Component: Database layer (models, ORM) 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

When attempting to use a new-style class for a model's Meta inner class (class Meta(object):), Django raises a TypeError because of two additional attributes that new-style classes have that old-style classes don't.

TypeError: 'class Meta' got invalid  attribute(s): __dict__,__weakref__

Admittedly, the documentation only shows old-style classes, but there's no mention of avoiding new-style classes. More to the point, once Python 3000 rolls around, all classes will be new-style by default, and this will become an instant problem.

Attachments (1)

7342-r7568.diff (973 bytes) - added by Marty Alchin 9 years ago.
Per Jacob, this patch simply ignores any attributes beginning with _, future-proofing this considerably.

Download all attachments as: .zip

Change History (3)

Changed 9 years ago by Marty Alchin

Attachment: 7342-r7568.diff added

Per Jacob, this patch simply ignores any attributes beginning with _, future-proofing this considerably.

comment:1 Changed 9 years ago by Jacob

Triage Stage: UnreviewedReady for checkin

comment:2 Changed 9 years ago by Jacob

Resolution: fixed
Status: newclosed

(In [7585]) Fixed #7342: Ignore any Meta options starting with '_', thus making it OK for Meta to be a newstyle class. Thanks, Gulopine.

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