Trying to catch integrity error with sqlaclhemey

Posted by Lostsoul on Stack Overflow See other posts from Stack Overflow or by Lostsoul
Published on 2012-07-03T15:12:20Z Indexed on 2012/07/03 15:15 UTC
Read the original article Hit count: 216

Filed under:
|

I'm having problems with trying to catch a error. I'm using pyramid/sqlalchemy and made a sign up form with email as the primary key. The problem is when a duplicate email is entered it raises a IntegrityError, so I'm trying to catch that error and provide a message but no matter what I do I can't catch it(the error keeps appearing).

    try:
        new_user = Users(email, firstname, lastname, password)
        DBSession.add(new_user)
        return HTTPFound(location = request.route_url('new'))
    except IntegrityError:
        message1 = "Yikes! Your email already exists in our system. Did you forget your password?"

I get the same message when I tried except exc.SQLAlchemyError (although I want to catch specific errors and not a blanket catch all).

Is there something wrong with my python syntax? or is there something I need to do special in sqlalchemy to catch it?

© Stack Overflow or respective owner

Related posts about python

Related posts about sqlalchemy