#2425 closed defect (fixed)
[patch] 'manage.py sql polls' fail with no error if invalid model
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Tools | Version: | dev |
Severity: | normal | Keywords: | |
Cc: | dev@… | Triage Stage: | Unreviewed |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Hi,
I just run throught the first part of the tutorial, until I get stuck for a few minutes with the python manage.py sql polls
:
$ python manage.py sql polls BEGIN; COMMIT; $
The model for this setup is :
from django.db import models class Poll(models.Model): question = models.CharField(maxlength=200) pub_date = models.DateiTimeField('date published') class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(maxlength=200) votes = models.IntergerField()
Of course, it is wrong, since 'DateiTimeField' and 'IntergerField' are mispelled, which is reported by python manage.py validate polls
:
$ python manage.py validate polls mysite.polls: 'module' object has no attribute 'DateiTimeField' 1 error found. $ python manage.py validate polls mysite.polls: 'module' object has no attribute 'IntergerField' 1 error found. $ python manage.py validate polls 0 errors found. $
But, I think python manage.py sql
should report the error too, or at least give a hint.
Attachments (1)
Change History (4)
comment:1 by , 18 years ago
Cc: | added |
---|
by , 18 years ago
comment:2 by , 18 years ago
Summary: | 'manage.py sql polls' fail with no error if invalid model → [patch] 'manage.py sql polls' fail with no error if invalid model |
---|
comment:3 by , 18 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
This can sort of be fixed by adding a call to validate() inside the execute_from_command_line() function in django/core/management.py. This will validate the installed models when sql/sqlall are run, and show up the errors quite nicely, before exiting with an AttributeError.
It'd be nicer to handle the AttributeError's better and to not display "0 errors found" when the models are fine, but I think this will involve modifying validate, get_validation_errors, or _check_for_validation_errors, and I didn't want to go near that.