This function does not accept data from the request. messages is populated by python-social-auth's exception middleware's process_exception() call (https://github.com/omab/python-social-auth/blob/master/social/apps/django_app/middleware.py).

An invariant of that code is one call produces one message, and if that invariant were violated this code could silently begin returning incorrect values. The most likely cause of invariant violation would be bumping the version of python-social-auth to a version with a different implementation of process_exception(). In that case, this assert would cause tests to fail loudly with a localized error.

Since there's no way for callers to recover from such an error, raising a more specific exception is not useful.