Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit on teardown #115

Merged
merged 3 commits into from
Jan 27, 2013
Merged

Commit on teardown #115

merged 3 commits into from
Jan 27, 2013

Conversation

mgax
Copy link
Contributor

@mgax mgax commented Jan 2, 2013

A common pattern is to automatically commit the database session when a request is handled, provided no exception was raised.

@mitsuhiko
Copy link
Contributor

I like this.

mitsuhiko added a commit that referenced this pull request Jan 27, 2013
@mitsuhiko mitsuhiko merged commit 2e029ac into pallets-eco:master Jan 27, 2013
@mgax mgax deleted the commit-on-teardown branch January 27, 2013 09:28
@stevesw
Copy link

stevesw commented May 19, 2013

Is it really safe to call session.commit() from @app.teardown_appcontext? What happens when session.commit() throws an exception?

@Turbo87
Copy link

Turbo87 commented May 28, 2013

@mgax it seems that this does not work when the debugger is used. when the exception is handled by the debugger the teardown function won't get called at all and on the next request the function is called without an exception which commits the changes.

@mgax
Copy link
Contributor Author

mgax commented May 31, 2013

@Turbo87, you're right, the session is not getting cleaned up. Looks like this happened before the patch too, but it only caused problems if the first reqest after the error did an explicit commit.

@mgax
Copy link
Contributor Author

mgax commented May 31, 2013

Digging around some more. The first request after the error pushes a new context, which causes the error's context to be popped, teardown_appcontext is called with no exception, and the autocommit function erroneously believes it's safe to commit.

Which, of course, is what you said, but I failed to parse. :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants