Opened 16 years ago
Closed 11 years ago
#8108 closed Bug (fixed)
Abstract Base Classes Shouldn't Trigger Auto-"app_label" Generation
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | dev |
Severity: | Normal | Keywords: | app_label, abstract-base-class |
Cc: | brooks.travis@… | Triage Stage: | Accepted |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
For some reason, importing an abstract base class causes Django to try and create an "app_label" for it. This isn't an issue, apparently, for ABCs defined in an app-level models.py module, but it causes an error (IndexError) if the ABC is in a top-level module in the python path. The current "fix" is to either move the ABC into an app's models.py file (not good for code re-use/separation) or supply a value for "app_label" in the ABC's class Meta. Perhaps adding a test to app_label generation that tests for _meta.abstract and skips on True might be a good idea?
Attachments (1)
Change History (11)
by , 16 years ago
comment:1 by , 16 years ago
comment:2 by , 16 years ago
milestone: | → post-1.0 |
---|---|
Triage Stage: | Unreviewed → Design decision needed |
comment:3 by , 16 years ago
milestone: | post-1.0 → 1.0 maybe |
---|
I don't like the patch (we should just not have an app name for ABCs), but the idea has merit because it allows more flexible design. Worth doing for 1.0 if we have time.
comment:4 by , 16 years ago
milestone: | 1.0 maybe → post-1.0 |
---|---|
Triage Stage: | Design decision needed → Accepted |
Malcolm now says that we don't have time.
comment:6 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Bug |
comment:9 by , 12 years ago
Component: | Core (Other) → Database layer (models, ORM) |
---|
comment:10 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
This problem came up during the app-loading refactor and was fixed. See #21794 for details.
Even if it is decided that all models should be defined within app-level modules it would be nice to have something better than an IndexError to point users at what the problem is. Attached is a very quick, minimally-tested patch with both changes included.