8000 Python3.11: sqlite3.connect passes more arguments to factory() · Issue #95132 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
Python3.11: sqlite3.connect passes more arguments to factory() #95132
Closed
@Steap

Description

@Steap

Hello,

Bug report

Consider the following code snippet:

$ cat /tmp/test.py

import sqlite3


class SqliteConnection(sqlite3.Connection):
    def __init__(self, *args, **kwargs):
        print(args)
        print(kwargs)
        super(SqliteConnection, self).__init__(*args, **kwargs)


db_path = '/tmp/foo.db'
sqlite3.connect(db_path, factory=SqliteConnection)

And the execution:

$ python3.10 /tmp/test.py
('/tmp/foo.db',)
{'factory': <class '__main__.SqliteConnection'>}

$ python3.11 /tmp/test.py
('/tmp/foo.db', 5.0, 0, '', 1, <class '__main__.SqliteConnection'>, 128, 0)
{}

The default values of sqlite3.connect's arguments are passed to the factory in
Python3.11, which was not the case in Python3.10. This means that code like
this will fail:

$ cat /tmp/failure.py

import sqlite3


class SqliteConnection(sqlite3.Connection):
    def __init__(self, *args, **kwargs):
        kwargs['timeout'] = 42
        super(SqliteConnection, self).__init__(*args, **kwargs)


db_path = '/tmp/foo.db'
sqlite3.connect(db_path, factory=SqliteConnection)
$ python3.10 /tmp/failure.py
$

$ python3.11 /tmp/failure.py
Traceback (most recent call last):
  File "/tmp/failure.py", line 11, in <module>
    sqlite3.connect(db_path, factory=SqliteConnection)
  File "/tmp/failure.py", line 7, in __init__
    super(SqliteConnection, self).__init__(*args, **kwargs)
TypeError: Connection() takes at most 8 arguments (9 given)

Your environment
This behaviour appeared in 185ecdc and affects
Python 3.11 and later.

It was mentioned in #93044 (see the
second bullet point in the reporter's message) but has not been fixed.

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixestopic-sqlite3triagedThe issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0