Opened 16 years ago

Closed 16 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

Description

Before:

In [1]: import models
---------------------------------------------------------------------------
<type 'exceptions.IndexError'>            Traceback (most recent call last)
 (strip my stuff)
...django/db/models/base.py 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 16 years ago.

Download all attachments as: .zip

Change History (4)

by Kenneth Arnold, 16 years ago

comment:1 by Kenneth Arnold, 16 years ago

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

comment:2 by Malcolm Tredinnick, 16 years ago

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 by Jacob, 16 years ago

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