Opened 8 years ago

Closed 8 years ago

#5311 closed (duplicate)

Validation of erroneous data model breaks with AttributeError instead of a useful message (like it used to)

Reported by: raik.gruenberg@… Owned by: nobody
Component: Core (Management commands) Version: master
Severity: Keywords: model validation sprintsept14
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


I've updated the data model of my django project and run sql <app_name> to check the changes.
I obviously made an error but rather than reporting it, the current svn revision of django breaks with the following traceback:

brickitserver|~/py/djbrickit> python sql repository
Traceback (most recent call last):
  File "", line 11, in <module>
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 180, in execute_manager
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 124, in execute
    command.execute(*args[1:], **options.__dict__)
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 33, in execute
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 60, in validate
    num_errors = get_validation_errors(s, app)
  File "/usr/lib/python2.5/site-packages/django/core/management/", line 72, in get_validation_errors
    rel_opts =
AttributeError: 'str' object has no attribute '_meta'

By contrast, svn revision 5000 gives this nice informative error message for the same command:

brickitserver|~/py/brickit/djbrickit> python sql repository
Error: One or more models did not validate:
djbrickit.repository: name 'BRICK_Format_CHOICES' is not defined

The offending part of my model looks like this:

class Biobrick:
   BRICK_FORMAT_CHOICES = ( ('classic', 'classic biobrick format'),... )
   brick_format = models.CharField( 'format of Biobrick', maxlength=30,
                                   default='classic' )

Attachments (1) (13.5 KB) - added by raik.gruenberg@… 8 years ago.
data model with errors

Download all attachments as: .zip

Change History (8)

Changed 8 years ago by raik.gruenberg@…

data model with errors

comment:1 Changed 8 years ago by raik.gruenberg@…

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

Update: There seem to be more actual errors in my data model. I am attaching the whole file in case anyone wants to reproduce the bug. That also means that revision 5000 is not necessarily better than 6031 but may only validate things in a different order.

comment:2 Changed 8 years ago by raik.gruenberg@…

Final update: The actual error in my model was the following:

    #: obligate
    brick_type = models.ForeignKey( 'type of Biobrick',
                                    verbose_name='biobrick type',

So I defined a ForeignKey without giving the correct Model class to refer to. The same can happen easily by simple spelling mistakes. Some more informative error message would be nice.

comment:3 Changed 8 years ago by ubernostrum

  • Component changed from Core framework to

comment:4 Changed 8 years ago by mtredinnick

  • Triage Stage changed from Unreviewed to Accepted

comment:5 Changed 8 years ago by Simon G. <dev@…>

  • Summary changed from Validation of errorneous data model breaks with AttributeError to Validation of erroneous data model breaks with AttributeError instead of a useful message (like it used to)

comment:6 Changed 8 years ago by Axis_of_Entropy

  • Keywords sprintsept14 added

I've also encountered this bug. I believe this is the problem in my model:

class Artwork(models.Model):
    tags = models.ManyToManyField('ZTag', blank=True, null=True)

class Tag(models.Model):
    name = models.SlugField(primary_key=True)

Notice that 'ZTag' in Artwork.tags should be 'Tag'. Changing that fixed the error. This happened when I was refactoring my model and missed one string literal, so I imagine it could happen to others.
So it looks like it affects ManyToManyField as well.
I'm going to look into and see if I can fix it.

comment:7 Changed 8 years ago by Axis_of_Entropy

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

I now think this bug is a duplicate of #3323 or maybe even #1662 is called many times in db.models.options

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