Opened 7 years ago

Closed 6 years ago

Last modified 6 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


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


from django.contrib.auth.models import AbstractBaseUser

class Example(db.Model):
$ ./ 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 Changed 7 years ago by Aymeric Augustin

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 Changed 7 years ago by Dan Loewenherz

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/", line 222, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "EXAMPLE/lib/python2.7/site-packages/django/core/management/", line 251, in execute
  File "EXAMPLE/lib/python2.7/site-packages/django/core/management/", line 277, in validate
    num_errors = get_validation_errors(s, app)
  File "EXAMPLE/lib/python2.7/site-packages/django/core/management/", 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/", line 165, in get_app_errors
  File "EXAMPLE/lib/python2.7/site-packages/django/db/models/", line 71, in _populate
    self.load_app(app_name, True)
  File "EXAMPLE/lib/python2.7/site-packages/django/db/models/", line 95, in load_app
    models = import_module('.models', app_name)
  File "EXAMPLE/lib/python2.7/site-packages/django/utils/", line 35, in import_module
  File "EXAMPLE/app/", line 4, in <module>
    class Example(db.Model):
NameError: name 'db' is not defined
NameError: name 'db' is not defined

comment:3 Changed 7 years ago by Aymeric Augustin

Triage Stage: UnreviewedDesign decision needed

comment:4 Changed 6 years ago by Florian Apolloner

Resolution: fixed
Status: newclosed

Imo this was fixed with [6a91b638423d].

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