{"action":"created","issue":{"url":"https://api.github.com/repos/miguelgrinberg/flasky/issues/58","labels_url":"https://api.github.com/repos/miguelgrinberg/flasky/issues/58/labels{/name}","comments_url":"https://api.github.com/repos/miguelgrinberg/flasky/issues/58/comments","events_url":"https://api.github.com/repos/miguelgrinberg/flasky/issues/58/events","html_url":"https://github.com/miguelgrinberg/flasky/issues/58","id":99903890,"number":58,"title":"db.session.commit() is not performed at the end of requests (prev \"Confirmation of users\")","user":{"login":"lucanaso","id":5300924,"avatar_url":"https://avatars.githubusercontent.com/u/5300924?v=3","gravatar_id":"","url":"https://api.github.com/users/lucanaso","html_url":"https://github.com/lucanaso","followers_url":"https://api.github.com/users/lucanaso/followers","following_url":"https://api.github.com/users/lucanaso/following{/other_user}","gists_url":"https://api.github.com/users/lucanaso/gists{/gist_id}","starred_url":"https://api.github.com/users/lucanaso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lucanaso/subscriptions","organizations_url":"https://api.github.com/users/lucanaso/orgs","repos_url":"https://api.github.com/users/lucanaso/repos","events_url":"https://api.github.com/users/lucanaso/events{/privacy}","received_events_url":"https://api.github.com/users/lucanaso/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":17,"created_at":"2015-08-09T15:02:58Z","updated_at":"2015-08-24T00:18:22Z","closed_at":null,"body":"*Update - begins*\r\n```db.session.commit()``` is not performed automatically at the end of each request, despite having ```SQLALCHEMY_COMMIT_ON_TEARDOWN = True``` in [config.py](https://github.com/lucanaso/flasky/blob/flasky/bug/userconfirmation/config.py#L8).\r\nThis issue was noted after analysing why user confirmation was not working properly.\r\nThe app is hosted on heroku (can be reached [here](https://flasky-forky.herokuapp.com)), is using Heroku Postgres and is based on this [repository](https://github.com/lucanaso/flasky), which is forked from the original 17d.\r\n*Update - ends*\r\n\r\nThe confirmation link does not update the ```current_user.confirmed``` to ```True``` and new registered users thus remain unconfirmed.\r\nIf the model column is changed by hand via shell, then the user is recognised as confirmed and the app behaves as expected.\r\n\r\nHere are the results of my analysis.\r\nBy examining the logs, the app behaviour is correct. I have the following lines from registration to confirmation of a new user:\r\n\r\n1. REGISTER, GET, with status 200\r\n```2015-08-07T08:50:09.059305+00:00 heroku[router]: at=info method=GET path=\"/auth/register\" ```\r\n2. REGISTER, POST, with status 302\r\n```2015-08-07T08:50:23.954973+00:00 heroku[router]: at=info method=POST path=\"/auth/register\" ```\r\n3. LOGIN, GET, with status 200\r\n```2015-08-07T08:50:24.181845+00:00 heroku[router]: at=info method=GET path=\"/auth/login\" ```\r\n4. (after clicking on the email confirmation link) CONFIRM, GET, with status 302\r\n```2015-08-07T08:50:35.040888+00:00 heroku[router]: at=info method=GET path=\"/auth/confirm/eyJleHAiOjE0Mzg5NDEwMjMsImlhdCI6MTQzODkzNzQyMywiYWxnIjoiSFMyNTYifQ.eyJjb25maXJtIjoxfQ.7hMYjfDmmwE_8c3kkw7jSdIRLWV-bPSJCCuYsy7bPeY\" ```\r\n5. (login is required here) LOGIN GET, with status 200\r\n```2015-08-07T08:50:35.259303+00:00 heroku[router]: at=info method=GET path=\"/auth/login?next=%2Fauth%2Fconfirm%2FeyJleHAiOjE0Mzg5NDEwMjMsImlhdCI6MTQzODkzNzQyMywiYWxnIjoiSFMyNTYifQ.eyJjb25maXJtIjoxfQ.7hMYjfDmmwE_8c3kkw7jSdIRLWV-bPSJCCuYsy7bPeY\" ```\r\n6. LOGIN POST, with status 302\r\n```2015-08-07T08:51:04.677048+00:00 heroku[router]: at=info method=POST path=\"/auth/login?next=%2Fauth%2Fconfirm%2FeyJleHAiOjE0Mzg5NDEwMjMsImlhdCI6MTQzODkzNzQyMywiYWxnIjoiSFMyNTYifQ.eyJjb25maXJtIjoxfQ.7hMYjfDmmwE_8c3kkw7jSdIRLWV-bPSJCCuYsy7bPeY\" ```\r\n7. CONFIRM GET, with status 302\r\n```2015-08-07T08:51:04.947112+00:00 heroku[router]: at=info method=GET path=\"/auth/confirm/eyJleHAiOjE0Mzg5NDEwMjMsImlhdCI6MTQzODkzNzQyMywiYWxnIjoiSFMyNTYifQ.eyJjb25maXJtIjoxfQ.7hMYjfDmmwE_8c3kkw7jSdIRLWV-bPSJCCuYsy7bPeY\" ```\r\n8. ROOT GET, with status 302\r\n```2015-08-07T08:51:05.156445+00:00 heroku[router]: at=info method=GET path=\"/\" ```\r\n9. UNCONFIRMED , with status 200  \r\n```2015-08-07T08:51:05.868130+00:00 heroku[router]: at=info method=GET path=\"/auth/unconfirmed\" ```\r\n\r\nFrom what I understand, the ```auth.before_app_request``` is redirecting the user to the unconfirmed page.\r\nHowever the flash message ```\"You have confirmed your account. Thanks!\"``` is displayed (see https://github.com/lucanaso/flasky/blob/master/app/auth/views.py#L72), therefore it looks like ```current_user.confirm``` returns ```True``` but it does not update the db (see https://github.com/lucanaso/flasky/blob/master/app/models.py#L147).\r\n\r\nI have forked the project at commit 17d and after that I have committed only some files for deploying on heroku and requirements.\r\n\r\nThe app is running on heroku at: https://flasky-forky.herokuapp.com/ you can try it yourself by registering and trying to confirm.\r\n\r\nWhat can be the cause of the user not being confirmed?"},"comment":{"url":"https://api.github.com/repos/miguelgrinberg/flasky/issues/comments/133971316","html_url":"https://github.com/miguelgrinberg/flasky/issues/58#issuecomment-133971316","issue_url":"https://api.github.com/repos/miguelgrinberg/flasky/issues/58","id":133971316,"user":{"login":"coreybrett","id":4440265,"avatar_url":"https://avatars.githubusercontent.com/u/4440265?v=3","gravatar_id":"","url":"https://api.github.com/users/coreybrett","html_url":"https://github.com/coreybrett","followers_url":"https://api.github.com/users/coreybrett/followers","following_url":"https://api.github.com/users/coreybrett/following{/other_user}","gists_url":"https://api.github.com/users/coreybrett/gists{/gist_id}","starred_url":"https://api.github.com/users/coreybrett/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreybrett/subscriptions","organizations_url":"https://api.github.com/users/coreybrett/orgs","repos_url":"https://api.github.com/users/coreybrett/repos","events_url":"https://api.github.com/users/coreybrett/events{/privacy}","received_events_url":"https://api.github.com/users/coreybrett/received_events","type":"User","site_admin":false},"created_at":"2015-08-24T00:18:22Z","updated_at":"2015-08-24T00:18:22Z","body":"It appears this also prevents users from changing passwords in Flasky.\r\nDoes this mean we should just use gunicorn 18 for now until flask 1.0 is released?\r\nAlso, according to the docs for Flask-SQLAlchemy, \"SQLALCHEMY_COMMIT_ON_TEARDOWN\" is not recommended, should we just add commit lines to the effected functions?"}}