KallyMilton / w2p-social-auth

Automatically exported from code.google.com/p/w2p-social-auth
Other
0 stars 0 forks source link

cannot catch python-social-auth exceptions #1

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
It's for some reason impossible to catch Exeptions from python-social-auth 
module. The exception type is not being resolved. instanceof also fails.

in controllers/plugin_social_auth.py

{{{
def complete():
    try:
        return do_complete(current.strategy,
                           login=lambda strat, user: login_user(user.row),
                           user=get_current_user())
    except Exception as e:
        #FIXME: For some reason I cannot create except only for SocialAuthBaseException or subclasses.
        # Those exception classes are not being resolved. Also instanceof() is not working.
        # Ideally I want to catch only SocialAuth Exceptions.
        if isinstance(e, HTTP):
            raise
        else:
            session.flash = e.message
            redirect(current.strategy.session_get('next'))
}}}

Original issue reported on code.google.com by muijsenb...@gmail.com on 25 Feb 2014 at 5:06

GoogleCodeExporter commented 9 years ago

Original comment by muijsenb...@gmail.com on 26 Feb 2014 at 2:55

GoogleCodeExporter commented 9 years ago

Original comment by muijsenb...@gmail.com on 2 Mar 2014 at 10:29

GoogleCodeExporter commented 9 years ago
Reopened issue.
I thought it was fixed but it isn't.

The problem seems to be that python-social-auth custom exceptions that are 
throw from the wrapped python-social-auth module ("social") have a module path 
relative to the wrapped module. The exceptions need to be caught in the 
wrapping plugin code but in the plugin code, the exceptions are imported with 
the complete module path. This results in isinstance() not working. Catching 
explicit exception type also does not work.

I added a workaround by checking the module of the exception:

def is_social_auth_exception(ex):
            return ex.__class__.__module__ in('social.exceptions', SocialAuthBaseException.__module__)

But this is hacky.

Original comment by muijsenb...@gmail.com on 2 Mar 2014 at 10:34