I am creating a Flask Application that connects to a locally-hosted MySQL database (Using SQL-Alchemy ORM). When a user creates an account, I have a method is_taken
and returns True
or False
depending on if a user with that username already exists.
Here is the method:
def is_taken(username):
q = session.query(User).filter(User.username == username).first()
return not (q is None)
Although not on a regular basis, the following error occurs at least once a day:
StatementError: (sqlalchemy.exc.InvalidRequestError) Can't reconnect until invalid transaction is rolled back [SQL: u'SELECT users.uid AS users_uid, users.username AS users_username, users.fullname AS users_fullname, users.password AS users_password, users.score AS users_score, users.totalattempted AS users_totalattempted, users.totalcorrect AS users_totalcorrect, users.settings AS users_settings \nFROM users \nWHERE users.username = %s \n LIMIT %s'] [parameters: [immutabledict({})]]
The error is triggered specifically on:
q = session.query(User).filter(User.username == username).first()
I appreciate the help!