ModelBase should only check `sys.modules` when it needs to
|Reported by:||Marty Alchin <gulopine@…>||Owned by:||adrian|
|Component:||Database layer (models, ORM)||Version:||master|
|Cc:||Triage Stage:||Ready for checkin|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
Currently, ModelBase.__new__ retrieves a model's module through sys.modules, in order to detect the model's app_label. However, this check is made even if the model provides an app_label on its Meta class. Since retrieval of app_label is the only use of this check, I've attached a patch that moves it into the if block, so it only executes if app_label was not provided in the model's Meta.
For what it's worth, this is important for a project of mine, as I'm hoping to generate models during runtime, rather than through Python source. I'm looking to design models interactively, even load them with data and test out relationships. Sort of a rapid-prototyping for Django, capable of being used even by non-coders, since it wouldn't rely on typing any Python code.
I know this is very much a corner case, but the fact remains that this check is really only used within that if statement, and it seems it could just as easily go there without any trouble.
Change History (17)
comment:1 Changed 9 years ago by Marty Alchin <gulopine@…>
- Needs documentation unset
- Needs tests unset
- Patch needs improvement unset
comment:2 Changed 9 years ago by Collin Grady <cgrady@…>
- Summary changed from [patch] ModelBase should only check `sys.modules` when it needs to to ModelBase should only check `sys.modules` when it needs to
comment:3 Changed 9 years ago by Simon G. <dev@…>
- Triage Stage changed from Unreviewed to Design decision needed
comment:6 Changed 9 years ago by Simon G. <dev@…>
- Triage Stage changed from Design decision needed to Ready for checkin
comment:10 Changed 9 years ago by mtredinnick
- Resolution set to fixed
- Status changed from new to closed