[New-bugs-announce] [issue43265] Improve sqlite3 backup error handling

Erlend Egeberg Aasland report at bugs.python.org
Fri Feb 19 04:10:02 EST 2021

New submission from Erlend Egeberg Aasland <erlend.aasland at innova.no>:

There are some issues with the error handling in pysqlite_connection_backup_impl():

1. ValueError is returned if the target connection equals source connection. Should be OperationalError, IMHO.

2. The aforementioned check is already performed by sqlite3_backup_init(), so we should just let SQLite take care of it and let _pysqlite_seterror() set the error if sqlite3_backup_init() returns NULL. This will also take care of 1.

3. The following comment seems to be wrong; errors are set on the connection object, not on the backup handle:
  /* We cannot use _pysqlite_seterror() here because the backup APIs do
     not set the error status on the connection object, but rather on
     the backup handle. */

After sqlite3_backup_finish(), we can just check the return code, and call _pysqlite_seterror() on the connection and return NULL. The mentioned comment can be removed.

Resolving these issues will save 18 lines of code, and make the backup function easier to maintain.


components: Library (Lib)
messages: 387297
nosy: berker.peksag, erlendaasland
priority: normal
severity: normal
status: open
title: Improve sqlite3 backup error handling
type: enhancement
versions: Python 3.10

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list