[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-31 Thread STINNER Victor


STINNER Victor  added the comment:

Nice!

--
nosy: +vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-28 Thread Erlend E. Aasland

Erlend E. Aasland  added the comment:

Thanks Luca, for the report, reproducer, and initial patch, Berker for helpful 
suggestion, and Łukasz, Pablo, & Victor for reviewing and merging.

--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-28 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 2a80893e5c023a73ccd32cc319f4f0404f548c00 by Erlend Egeberg 
Aasland in branch '3.10':
[3.10] bpo-27334: roll back transaction if sqlite3 context manager fails to 
commit (GH-26202) (GH-27943)
https://github.com/python/cpython/commit/2a80893e5c023a73ccd32cc319f4f0404f548c00


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-25 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 52702e8ba0d777ac92ec36038213976545c4759e by Erlend Egeberg 
Aasland in branch '3.9':
[3.9] bpo-27334: roll back transaction if sqlite3 context manager fails to 
commit (GH-26202) (GH-27944)
https://github.com/python/cpython/commit/52702e8ba0d777ac92ec36038213976545c4759e


--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-25 Thread Łukasz Langa

Łukasz Langa  added the comment:


New changeset a3c11cebf174e0c822eda8c545f7548269ce7a25 by Erlend Egeberg 
Aasland in branch 'main':
bpo-27334: Fix reference leak introduced by GH-26202 (GH-27942)
https://github.com/python/cpython/commit/a3c11cebf174e0c822eda8c545f7548269ce7a25


--
nosy: +lukasz.langa

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-25 Thread Erlend E. Aasland


Change by Erlend E. Aasland :


--
pull_requests: +26390
pull_request: https://github.com/python/cpython/pull/27944

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-25 Thread Erlend E. Aasland


Change by Erlend E. Aasland :


--
pull_requests: +26389
pull_request: https://github.com/python/cpython/pull/27943

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-25 Thread Erlend E. Aasland


Change by Erlend E. Aasland :


--
pull_requests: +26388
pull_request: https://github.com/python/cpython/pull/27942

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-08-25 Thread Pablo Galindo Salgado


Pablo Galindo Salgado  added the comment:


New changeset 7ecd3425d45a37efbc745788dfe21df0286c785a by Erlend Egeberg 
Aasland in branch 'main':
bpo-27334: roll back transaction if sqlite3 context manager fails to commit 
(GH-26202)
https://github.com/python/cpython/commit/7ecd3425d45a37efbc745788dfe21df0286c785a


--
nosy: +pablogsal

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-05-18 Thread Erlend E. Aasland


Erlend E. Aasland  added the comment:

> I believe the reason for this problem is that the exception happened in the
> implicit `commit` that is run on exiting the context manager, rather than
> inside it. In fact the exception is in the `pass` line rather than in the
> `execute` line. This exception did not trigger a `rollback` because the it
> happened after `pysqlite_connection_exit` checks for exceptions.

FYI, here's the SQLite API interaction from the context manager, 
chronologically (using the test from the PR). (I only show the relevant 
arguments passed to the API, for readability.)

sqlite3_prepare_v2("insert into t values('test')", insert_stmt) => SQLITE_OK
sqlite3_get_autocommit()
# Note, the insert statement is now prepared, but not executed yet.

# Transaction control now begins
sqlite3_prepare_v2("BEGIN ", begin_stmt) => SQLITE_OK
sqlite3_step(begin_stmt) => SQLITE_DONE
sqlite3_finalize(begin_stmt)

# Here, the insert statement is executed
sqlite3_bind_blob_parameter_count(insert_stmt)
sqlite3_step(insert_stmt) => SQLITE_DONE
sqlite3_changes()
sqlite3_last_insert_rowid()
sqlite3_reset(insert_stmt) => SQLITE_OK
sqlite3_get_autocommit()

# Enter __exit__: no exception has been raised, so it tries to commit
sqlite3_prepare_v2("commit", commit_stmt) => SQLITE_OK
sqlite3_step(commit_stmt) => SQLITE_BUSY (database is locked)
sqlite3_finalize(commit_stmt)

# After the fix, rollback is now executed
sqlite3_prepare_v2("rollback", rollback_stmt)
sqlite3_step(rollback_stmt) => SQLITE_DONE
sqlite3_finalize(rollback_Stmt)


As you can see, it does not fail (and raise an exception) until commit is 
issued inside __exit__.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27334] [sqlite3] context manager leaves db locked if commit fails in __exit__

2021-05-17 Thread Erlend E. Aasland


Erlend E. Aasland  added the comment:

> In fact the exception is in the `pass` line rather than in the `execute` line.

I can reproduce this without the `pass` line.

I've taken the liberty to create a PR based on your patch, Luca. Berker's 
comments have been addressed in the PR.

--
title: pysqlite3 context manager not performing rollback when a database is 
locked elsewhere for non-DML statements -> [sqlite3] context manager leaves db 
locked if commit fails in __exit__
versions: +Python 3.10, Python 3.11, Python 3.9 -Python 3.5, Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com