Forums

Flask application creating new sessions and preventing me from updating or deleting database entries

Hi there,

I am really stuck with an issue with my flask application that has arisen when I have uploaded my application onto the pythonanywhere servers although does not occur when I run it through my local host. When using pythoanywhere, though I am able to add database entries, I cannot delete or update them because the flask session keeps changing. The error message I am getting in the log appears when I try to delete a post and is as follows:

InvalidRequestError: Object '<Post at 0x7f47a968d350>' is already attached to session '1' (this is '5')

I was hoping that someone might have had a similar issue and would be able to offer me some guidance because I am having a lot of trouble trying to get this working at the moment.

Thanks

Are you using WhooshAlchemy? I see you just posted something in a different thread about Whoosh, and this Stack Overflow post looks like it might be relevant.

Hi, thanks for getting back to me. The issue was indeed WhooshAlchemy and I have managed to get it working now. The problem I had was caused by a clash that occurs between flask sqlalchemy and flask whoosh search that is described here http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-xvi-debugging-testing-and-profiling. The issue causes flask to keep creating new database sessions and prevents you from delete or updating database entries. This issue has been fixed in more recent versions of whoosh although it seems that the version pre installed on the system packages does not include this fix.

I fixed this updating the system packages with - pip install --user Flask-WhooshAlchemy==0.56.

The error message I was getting was InvalidRequestError: Object '<Post at 0x7f47a968d350>' is already attached to session '1' (this is '5') in case anybody comes across the same issue in the future.