[patch] Tighten subclass check at top of db.models.base.ModelBase.__new__.
|Reported by:||Owned by:||Malcolm Tredinnick|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
The "not bases or bases == (object,)" check at the top of ModelBase.new assumes that if the class-to-be has any bases, that one of them will be Model.
It cropped up while writing a mixin superclass for models that provided some new service-ish functionality for my app. The mixin requires a metaclass of its own. To satisfy guido's metaclass resolution rules, my mixin's metaclass extends ModelBase. The catch: when evaluating my mixin definition, ModelBase is invoked. My mixin has a superclass, so it slips past the check, and things explode.
My own metaclass can opt to check the Model subclass condition itself, and not call super(..).new, but that is hackish. Please consider the attached patch instead.
Thanks for listening!
Change History (15)
comment:3 Changed 10 years ago by
|Owner:||changed from Adrian Holovaty to Malcolm Tredinnick|
|Triage Stage:||Design decision needed → Ready for checkin|
comment:5 Changed 10 years ago by
|Patch needs improvement:||set|
|Status:||closed → reopened|
comment:7 Changed 10 years ago by
|Patch needs improvement:||unset|
|Triage Stage:||Ready for checkin → Unreviewed|