Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#2425 closed defect (fixed)

[patch] 'manage.py sql polls' fail with no error if invalid model

Reported by: jon@… Owned by: Adrian Holovaty
Component: Tools Version: master
Severity: normal Keywords:
Cc: dev@… Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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)

2425.diff (492 bytes) - added by dev@… 10 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 Changed 10 years ago by Simon Greenhill

Cc: dev@… added

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.

Changed 10 years ago by dev@…

Attachment: 2425.diff added

comment:2 Changed 10 years ago by dev@…

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 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [3802]) Fixed #2425 -- Call validate() as part of generating SQL in order to catch a
few more errors. Thanks, Simon Greenhill.

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