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:

class Meta:
  permissions = (
    ("can_drive", "Can drive"),
    ("can_vote", "Can vote in elections"),
    ("can_drink", "Can drink alcohol"),   # <== This comma is important!

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.


  • # Reply from Ronny at 08:35 on 24 Jan 2009

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

  • # Reply from Luke Jernejcic at 04:06 on 3 Aug 2009

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

  • # Reply from dd at 03:50 on 17 Oct 2009

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

Comments are closed.