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

SQLAlchemy code samples don't close session #52

Closed
luhn opened this issue Jul 10, 2012 · 5 comments
Closed

SQLAlchemy code samples don't close session #52

luhn opened this issue Jul 10, 2012 · 5 comments

Comments

@luhn
Copy link

luhn commented Jul 10, 2012

The code samples in database/sqlalchemy.html don't close the session when the request is finished.

I was running into some problems with overflows in the SQLAlchemy connection pool, and modified the code to this:

def db(self):
    def cleanup(self):
        self.db.close()
    self.add_finished_callback(cleanup)
    return self.registry.settings['sessionmaker']()

Which so far seems to be working.

@mmerickel
Copy link
Member

You're correct. This also needs to be updated to use config.set_request_property.

@luhn
Copy link
Author

luhn commented Jul 13, 2012

What's config.set_request_property?

kusut added a commit to kusut/pyramid_cookbook that referenced this issue Jan 21, 2013
@kusut
Copy link
Contributor

kusut commented Jan 21, 2013

I made changes as @luhn suggested.

If I want to update using add_request_method, should I remove the "changing request factory" way? Changing request factory provides an easy way to close session. With add_request_method, we have to do add_finished_callback to close session separately (or just warn about unclosed session?).

Thoughts?

@mmerickel
Copy link
Member

What am I missing? With a request factory or a request method I would have used add_finished_callback to close the session.

kusut added a commit to kusut/pyramid_cookbook that referenced this issue Jan 23, 2013
mmerickel added a commit that referenced this issue Jan 23, 2013
improve sqla recipe. also #52
@mmerickel
Copy link
Member

Closed via 4a423fa.

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

Successfully merging a pull request may close this issue.

3 participants