Opened 7 years ago

Closed 7 years ago

#7342 closed (fixed)

Using a new-style class for Meta raises an exception

Reported by: Gulopine Owned by: Gulopine
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 Gulopine 7 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 7 years ago by Gulopine

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

comment:1 Changed 7 years ago by jacob

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

comment:2 Changed 7 years ago by jacob

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

(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