[Django]-Django model.DoesNotExist exception somehow replaced with an AttributeError

3πŸ‘

βœ…

It was because of incorrect syntax elsewhere in the project, that caught multiple exceptions like this:

try:
   do_something()
except AttributeError, Profile.DoesNotExist:
   pass

When it should have been this:

try:
   do_something()
except (AttributeError, Profile.DoesNotExist):
   pass

What was happening was that when this happened, AttributeError got assigned to Profile.DoesNotExist in memory, so when it was raised later, it was the wrong exception.

Thanks to this post for helping.

πŸ‘€seddonym

Leave a comment