Opened 8 years ago

Closed 8 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: master
Severity: Keywords:
Cc: kenneth.arnold@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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 8 years ago.

Download all attachments as: .zip

Change History (4)

Changed 8 years ago by Kenneth Arnold

comment:1 Changed 8 years ago by Kenneth Arnold

Cc: kenneth.arnold@… added
Has patch: set
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

comment:2 Changed 8 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 8 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