Opened 14 years ago

Closed 14 years ago

#8195 closed (worksforme)

Importing models from same directory throws unhelpful exception (trying to get app_label)

Reported by: Kenneth Arnold Owned by: nobody
Component: Database layer (models, ORM) Version: dev
Severity: Keywords:
Cc: kenneth.arnold@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no



In [1]: import models
<type 'exceptions.IndexError'>            Traceback (most recent call last)
 (strip my stuff)
...django/db/models/ in __new__(cls, name, bases, attrs)
     54             # For 'django.contrib.sites.models', this would be 'sites'.
     55             model_module = sys.modules[new_class.__module__]
---> 56             kwargs = {"app_label": model_module.__name__.split('.')[-2]}
     57         else:
     58             kwargs = {}

After attached patch, the relative import succeeds.

Attachments (1)

django-relative-import-app-label.patch (1.2 KB) - added by Kenneth Arnold 14 years ago.

Download all attachments as: .zip

Change History (4)

Changed 14 years ago by Kenneth Arnold

comment:1 Changed 14 years ago by Kenneth Arnold

Cc: kenneth.arnold@… added
Has patch: set

comment:2 Changed 14 years ago by Malcolm Tredinnick

You haven't clearly explained the problem you are trying to fix. There's lots of code around that does import models without any problems, so that particular line of code isn't fundamentally broken.

Please provide some steps to replicate the problem you are seeing, then we can work out if the solution is appropriate.

comment:3 Changed 14 years ago by Jacob

Resolution: worksforme
Status: newclosed

Marking worksforme; kcarnold, please feel free to reopen when you provide the details Malcolm asked for.

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