Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Test Time Django TDD

Jonathan Wadsworth
Jonathan Wadsworth
20,196 Points

Why are the tests failing with a TypeError?

This is the error I'm getting. My model looks like this: from django.db import models

from django.db import models


class Performer(models.Model):
    name = models.CharField(max_length=255)

    def __str__(self):
        return self.name


class Song(models.Model):
    title = models.CharField(max_length=255)
    artist = models.CharField(max_length=255)
    performer = models.ForeignKey(Performer)
    duration = models.IntegerField(default=0)

    def __str__(self):
        return '{title} by {artist}'.format(title=self.title, artist=self.artist)

This is the error:

ERROR: test_song_string (songs.tests.SongModelTests)                                                           
String version of Song should contain the title and artist                                                     
----------------------------------------------------------------------                                         
Traceback (most recent call last):                                                                             
  File "/home/treehouse/workspace/karaoke/songs/tests.py", line 25, in test_song_string                        
    performer=self.performer)                                                                                  
  File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages/django/db/models/manager.py", line 122, in manager_method                                                                                                 
    return getattr(self.get_queryset(), name)(*args, **kwargs)                                                 
  File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages/django/db/models/query.py", line 399, in create                                                                                                           
    obj = self.model(**kwargs)                                                                                 
  File "/usr/local/pyenv/versions/3.5.0/lib/python3.5/site-packages/django/db/models/base.py", line 443, in __init__                                                                                                          
    raise TypeError("'%s' is an invalid keyword argument for this function" % list(kwargs)[0])                 
TypeError: 'length' is an invalid keyword argument for this function

Can you show your tests? That's where the error is being generated from according to the traceback.

1 Answer

Jonathan Wadsworth
Jonathan Wadsworth
20,196 Points

Got it. This exact question was answered a long time ago. I just didn't see it because the discussion topics weren't listed below the challenge. When I clicked "Get Help" it didn't bring up this question.

The answer here is that the field name "duration" in the Song model is the wrong name for the field. Even though the README.txt says "Song model should ... have a duration" it actually needs to be named "length" to pass the test. Phew. What a nightmare.

Please be more clear in the future with the readme.