mthorley wrote: > I just upgraded to django 1.0 and started getting this error. I was > already using newforms and am quite surprised and dumbfounded by the > errror. Generally this error would be caused by a missing comma in a > tuple, but that appears to not be my case. > > I added some print statements (to django/forms/fields.py) and even > over-wrote the variable in question to try and isolate the problem but > have had no success. > > Below is a snip of the code in question, with my added debugging > statements. Note that even when I override "v" with a tuple containing > two string, I still get the error. > > That almost makes me think something is broken with my python install, > however when I execute a similar statement from the python shell, it > works fine, and when I run the server with a different installation of > python I still get the error. > > Below the code snip is the output I get in my terminal when the below > code runs. At the bottom of this post is a complete trace back of the > error. > > I'm sure now that I am over looking something very obvious, and would > be very appreciate to any one who can point it out to me. > > Thanks > -- > matthew > > # snip from django/forms/fields.py > def valid_value(self, value): > "Check to see if the provided value is a valid choice" > for k, v in self.choices: > v = ('test', 'value') # for debugging > if type(v) in (tuple, list): > # This is an optgroup, so look inside the group for > options > print v, type(v), 'len =', len(v), 'v[0] =', v[0], > 'v[1] =', v[1] # added for debugging > for k2, v2 in v: > if value == smart_unicode(k2): > return True > else: > if value == smart_unicode(k): > return True > return False > > # server output > Django version 1.0-final-SVN-783, using settings 'sample.settings' > Development server is running at http://127.0.0.1:8000/ > Quit the server with CONTROL-C. > ('test', 'value') <type 'tuple'> len = 2 v[0] = test v[1] = value > [07/Oct/2008 09:40:59] "POST /free_personality_test/ HTTP/1.1" 500 > 86171 > > # django traceback > Environment: > > Request Method: POST > Request URL: http://localhost:8000/free_personality_test/ > Django Version: 1.0-final-SVN-783 > Python Version: 2.5.2 > Installed Applications: > ['django.contrib.admin', > 'django.contrib.auth', > 'django.contrib.comments', > 'django.contrib.contenttypes', > 'django.contrib.humanize', > 'django.contrib.markup', > 'django.contrib.sessions', > 'django.contrib.sites', > 'colorcode.profiler', > 'colorcode.accounts', > 'colorcode.email_campaigns', > 'colorcode.coupons', > 'colorcode.feedback', > 'colorcode.registration', > 'colorcode.accounts', > 'colorcode.unregistered_users', > 'colorcode'] > Installed Middleware: > ('django.middleware.common.CommonMiddleware', > 'django.contrib.sessions.middleware.SessionMiddleware', > 'django.contrib.auth.middleware.AuthenticationMiddleware', > 'djangologging.middleware.LoggingMiddleware', > 'django.middleware.doc.XViewMiddleware', > 'django.middleware.transaction.TransactionMiddleware', > 'colorcode.profiler.middleware.PersonalityProfileMiddleware') > > Traceback: > File "/Users/matthew/sandbox/cc-django-1.0-integration/lib/django/core/ > handlers/base.py" in get_response > 86. response = callback(request, *callback_args, > **callback_kwargs) > File "/Users/matthew/sandbox/cc-django-1.0-integration/site/colorcode/ > profiler/views.py" in personality_assessment > 181. strengthslims_form.is_valid() and \ > File "/Users/matthew/sandbox/cc-django-1.0-integration/lib/django/ > forms/forms.py" in is_valid > 120. return self.is_bound and not bool(self.errors) > File "/Users/matthew/sandbox/cc-django-1.0-integration/lib/django/ > forms/forms.py" in _get_errors > 111. self.full_clean() > File "/Users/matthew/sandbox/cc-django-1.0-integration/lib/django/ > forms/forms.py" in full_clean > 224. value = field.clean(value) > File "/Users/matthew/sandbox/cc-django-1.0-integration/lib/django/ > forms/fields.py" in clean > 648. if not self.valid_value(value): > File "/Users/matthew/sandbox/cc-django-1.0-integration/lib/django/ > forms/fields.py" in valid_value > 658. for k2, v2 in v: > > Exception Type: ValueError at /free_personality_test/ > Exception Value: too many values to unpack
The issue here is that the for statement expects a *sequence* of two-element tuples to iterate over and, for whatever reason, it's only getting a single tuple. Hence the error message. I hope this gives you a start on finding out what's actually wrong ... regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---