Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

bpo-34580: Clarify calling close when connection is used in a context manager #9079

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

Merged
merged 9 commits into from
May 19, 2019

Conversation

tirkarthi
Copy link
Member

@tirkarthi tirkarthi commented Sep 6, 2018

Add an extra note that the connection object doesn't call close in a context manager.

Thanks

https://bugs.python.org/issue34580

@bedevere-bot bedevere-bot added the docs Documentation in the Doc dir label Sep 6, 2018
@tirkarthi tirkarthi changed the title bpo34580: Clarify calling close when connection is used in a context manager bpo-34580: Clarify calling close when connection is used in a context manager Sep 6, 2018
Doc/library/sqlite3.rst Outdated Show resolved Hide resolved
Doc/includes/sqlite3/connect_db_1.py Outdated Show resolved Hide resolved
Doc/includes/sqlite3/connect_db_2.py Outdated Show resolved Hide resolved
Doc/includes/sqlite3/ctx_manager.py Show resolved Hide resolved
Doc/includes/sqlite3/execute_3.py Outdated Show resolved Hide resolved
Doc/includes/sqlite3/row_factory.py Show resolved Hide resolved
Doc/includes/sqlite3/shortcut_methods.py Show resolved Hide resolved
@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@tirkarthi
Copy link
Member Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@berkerpeksag: please review the changes made to this pull request.

@tirkarthi
Copy link
Member Author

tirkarthi commented Sep 28, 2018

I have deleted the unused files and added comments about usage of close in the PR comments. In addition to that I noticed examples in executescript and iterdump where also missing close. I have added them.

One thing I noticed with the backup example was that connection object was initialized in the context manager itself thus the commit would be called but the connection object will be de-allocated without closing the connection. I hope I am correct here given my understanding of the PR and context managers. So I have changed the current example

Current example :

con = sqlite3.connect('existing_db.db')
with sqlite3.connect('backup.db') as bck:
    con.backup(bck, pages=1, progress=progress)

Example in the PR :

con = sqlite3.connect('existing_db.db')
bck = sqlite3.connect('backup.db')
with bck:
    con.backup(bck, pages=1, progress=progress)
bck.close()
con.close()

Apologies for multiple commits that might have spammed you after notifying with the bot. I added con.backup(bck, pages=1, progress=progress) and then realized it needs to be wrapped in a with statement so that the changes are committed in the transaction.

Thanks for the review!

@tirkarthi
Copy link
Member Author

Friendly ping @berkerpeksag :)

@csabella csabella requested a review from berkerpeksag May 17, 2019 23:31
@berkerpeksag berkerpeksag merged commit 287b84d into python:master May 19, 2019
@miss-islington
Copy link
Contributor

Thanks @tirkarthi for the PR, and @berkerpeksag for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 19, 2019
…GH-9079)

The sqlit3.Connection object doesn't call its close() method when it's used
as a context manager.
(cherry picked from commit 287b84d)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
@bedevere-bot
Copy link

GH-13429 is a backport of this pull request to the 3.7 branch.

berkerpeksag pushed a commit that referenced this pull request May 19, 2019
The sqlite3.Connection object doesn't call its close() method when it's used
as a context manager.

(cherry picked from commit 287b84d)

Co-authored-by: Xtreak <tir.karthi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.