Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#24981 closed Uncategorized (invalid)

Importing an abstract model from a bare package fails.

Reported by: Stavros Korokithakis Owned by: nobody
Component: Uncategorized Version: 1.8
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have an abstract model called CharIDModel in myproject/utils/init.py. If I import it as "from utils import CharIDModel" and inherit from it, makemigrations crashes with:

Traceback (most recent call last):
  File "./manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/user/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/home/user/.virtualenvs/project/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/home/user/.virtualenvs/project/local/lib/python2.7/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/user/.virtualenvs/project/local/lib/python2.7/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/home/user/.virtualenvs/project/local/lib/python2.7/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
  File "/home/user/Code/Django/project/main/models.py", line 11, in <module>
    from utils import dt_today, CharIDModel
  File "/home/user/Code/Django/project/utils/__init__.py", line 48, in <module>
    class CharIDModel(models.Model):
  File "/home/user/.virtualenvs/project/local/lib/python2.7/site-packages/django/db/models/base.py", line 115, in __new__
    kwargs = {"app_label": package_components[app_label_index]}
IndexError: list index out of range

Change History (2)

comment:1 by Tim Graham, 10 years ago

Resolution: invalid
Status: newclosed

Based on the traceback, it looks like you're using Django 1.7. In Django 1.8 it looks like that IndexError is caught and you should get an error message like 'Unable to detect the app label for model "%s." Ensure that its module, "%s", is located inside an installed app.'" You might try adding an explicit Meta.app_label to your abstract model. Feel free to reopen if you continue to suspect a bug and can provide a sample project running Django 1.8, as 1.7 is only receiving security updates at this time. Thanks!

comment:2 by Stavros Korokithakis, 10 years ago

Thank you, I'll just upgrade to 1.8!

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