Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#19390 closed Bug (fixed)

NameError in models throws ambiguous message when running syncdb

Reported by: Dan Loewenherz Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5-beta-1
Severity: Normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When I start a Django 1.5 repo and forget to import a required library, I get a very ambiguous error when running ./manage.py syncdb

My models.py

from django.contrib.auth.models import AbstractBaseUser

class Example(db.Model):
    pass
$ ./manage.py syncdb
NameError: name 'db' is not defined

The file path where this error occurs should probably be noted to users. I can imagine it getting tough to track down when in a large project with lots of apps.

Change History (4)

comment:1 by Aymeric Augustin, 12 years ago

This is a common Python error message, I wouldn't call it ambiguous. You can obtain the full traceback with the --traceback option.

Maybe Django should display tracebacks by default...

comment:2 by Dan Loewenherz, 12 years ago

I think the traceback is a bit overkill, but just showing the NameError without *any* context isn't really enough to do anything about it. I would at least show the path of the file where it originated from.

Also, when running --traceback, it displays the exception twice:

Traceback (most recent call last):
  File "EXAMPLE/lib/python2.7/site-packages/django/core/management/base.py", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "EXAMPLE/lib/python2.7/site-packages/django/core/management/base.py", line 251, in execute
    self.validate()
  File "EXAMPLE/lib/python2.7/site-packages/django/core/management/base.py", line 277, in validate
    num_errors = get_validation_errors(s, app)
  File "EXAMPLE/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors
    for (app_name, error) in get_app_errors().items():
  File "EXAMPLE/lib/python2.7/site-packages/django/db/models/loading.py", line 165, in get_app_errors
    self._populate()
  File "EXAMPLE/lib/python2.7/site-packages/django/db/models/loading.py", line 71, in _populate
    self.load_app(app_name, True)
  File "EXAMPLE/lib/python2.7/site-packages/django/db/models/loading.py", line 95, in load_app
    models = import_module('.models', app_name)
  File "EXAMPLE/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "EXAMPLE/app/models.py", line 4, in <module>
    class Example(db.Model):
NameError: name 'db' is not defined
NameError: name 'db' is not defined

comment:3 by Aymeric Augustin, 12 years ago

Triage Stage: UnreviewedDesign decision needed

comment:4 by Florian Apolloner, 12 years ago

Resolution: fixed
Status: newclosed

Imo this was fixed with [6a91b638423d].

Last edited 12 years ago by Florian Apolloner (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top