james mckay dot net

because there are few things that are less logical than business logic

Django: ValueError: too many values to unpack

I came across this error this morning on a Django project that I’m working on in my spare time. I was trying to add some custom permissions to one of the models, as outlined in the documentation, only to have it choke with this message when I ran manage.py syncdb.

A bit of Googling got me to this site, but unfortunately it’s in Polish. Never mind, Google Translate managed to give me enough information. Turns out that I had missed out a comma that I didn’t think was necessary:

[code lang=”python”]
class Meta:
permissions = (
("can_drive", "Can drive"),
("can_vote", "Can vote in elections"),
("can_drink", "Can drink alcohol"), # <== This comma is important!
)
[/code]

Hmmm, I always thought that last comma in Python was only an optional extra in case you decided to add an extra item to the end of a tuple and forgot to add it in to the previous line. Seems it does have some obscure but significant semantic importance after all.

Comments

3 responses to “Django: ValueError: too many values to unpack”

  1. Ronny avatar

    Thanks for posting this. It saved me a lot of time. Cheers!

  2. Luke Jernejcic avatar
    Luke Jernejcic

    I just wanted to add that I got this error because I was missing the comma on my PAGE_TEMPLATES tuple. FYI.

  3. dd avatar

    create lists with defined number of elements
    list = [] * 100
    enjoy