Great point Karen.  It hadn't occurred to me that it could be a later
occurrence that could lead to python thinking it was local.  Later:
except ValueError, KeyError

After changing it to:
except (ValueError, KeyError)
the issue is resolved.

Thanks so much!
Casey

On Mon, Apr 9, 2012 at 11:20 AM, Karen Tracey <kmtra...@gmail.com> wrote:
> On Mon, Apr 9, 2012 at 11:09 AM, Casey Greene <csgre...@princeton.edu> wrote:
>> I have this very baffling error that I'm dealing with at the moment.
>> I'm maintaining someone else's code and I'm getting this error for
>> some queries with a try, except block in a view.  It seems that the
>> queries that lead to the error are ones where there is, in fact, a
>> KeyError.  I've actually manged to narrow it down to a pretty simple
>> test case though.  Within the view, I can do this (first few lines):
>>
>> def gene_view(request, slug=None, gene=None, org=None, template=None):
>>   print(KeyError)
>>
>> and I get this exception with django 1.4 (if it matters):
>> UnboundLocalError at /predictions/gene/
>> local variable 'KeyError' referenced before assignment
>
> Python thinks KeyError is a local variable, thus it sounds like code
> in the view subsequent to where KeyError is caught makes an assignment
> to KeyError. So search later in the view for where KeyError is
> mis-assigned.
>
> Karen
> --
> http://tracey.org/kmt/
>
> --
> 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 
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at 
> http://groups.google.com/group/django-users?hl=en.
>

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to