Code

Opened 20 months ago

Closed 16 months ago

Last modified 16 months ago

#19390 closed Bug (fixed)

NameError in models throws ambiguous message when running syncdb

Reported by: dloewenherz 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.

Attachments (0)

Change History (4)

comment:1 Changed 20 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

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 20 months ago by dloewenherz

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 Changed 19 months ago by aaugustin

  • Triage Stage changed from Unreviewed to Design decision needed

comment:4 Changed 16 months ago by apollo13

  • Resolution set to fixed
  • Status changed from new to closed

Imo this was fixed with 6a91b638423d.

Version 0, edited 16 months ago by apollo13 (next)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.