It’s not always this code chunk but this is the most recent. It seems to be random, any thoughts?
try:
u = User.objects.get(email__iexact=useremail)
except User.DoesNotExist:
...
Throws this error, randomly.
File "/srv/myapp/registration/models.py", line 23, in get_or_create_user
u = User.objects.get(email__iexact=useremail)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/manager.py", line 132, in get
return self.get_query_set().get(*args, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/django/db/models/query.py", line 349, in get
% self.model._meta.object_name)
TypeError: ‘DoesNotExist’ object is not callable
As Chris says in the comments above, your snippet is valid. Somewhere else in your code, you may be catching exceptions incorrectly.
You may have something like:
instead of:
Without the parentheses, the except statement is equivalent to the following in Python 2.6+
The instance of the
User.MultipleObjectsReturnedexception overwritesUser.DoesNotExist.When the same process handles a different request later on, you get
the
TypeErrorbecause your code is trying to call the exception instance which has replacedUser.DoesNotExist.