GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Python3.11: sqlite3.connect passes more arguments to factory() · Issue #95132 · python/cpython

Python3.11: sqlite3.connect passes more arguments to factory() #95132

New issue
Copy link
New issue
Copy link
Closed
#95146
Closed
Python3.11: sqlite3.connect passes more arguments to factory()#95132
#95146
Copy link
Assignees
erlend-aasland
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixestopic-sqlite3triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@Steap
Steap
opened on Jul 22, 2022
Issue body actions

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.

Reacted by Erlend E. Aasland

Activity

  1. Steap
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Jul 22, 2022
  2. kumaraditya303
    assigned
    erlend-aasland
    on Jul 22, 2022
  3. kumaraditya303
    added
    3.11only security fixesonly security fixes
    3.12only security fixesonly security fixes
    on Jul 22, 2022
  4. erlend-aasland
    added this to sqlite3 issueson Jul 22, 2022
  5. erlend-aasland
    moved this to TODO: Bugs in sqlite3 issueson Jul 22, 2022
  6. erlend-aasland
    added
    topic-sqlite3
    triagedThe issue has been accepted as valid by a triager.The issue has been accepted as valid by a triager.
    on Jul 22, 2022
  7. erlend-aasland commented on Jul 22, 2022

    @erlend-aasland
    erlend-aasland
    on Jul 22, 2022
    Contributor
    More actions

    Thanks for the report. This is unfortunate. Reverting the offending commit is going to be hairy; there has been a lot of changes since that point in time.

    The only thing sqlite3.connect needs in order to relay the call to sqlite3.Connection.__init__ is: *args, **kwargs, and factory. Unfortunately, doing such a manoeuvre is impossible (AFAIK) with Argument Clinic. Trying to bend AC to our needs, could be an option. Another option is to just parse the factory argument manually (kinda like the old code), and pass the rest using vector call (or PyObject_Call). I've already tried to look for a way to do these things because of keyword-only argument needs in another PR (#93823); I might actually be able to adopt that approach.

    @serhiy-storchaka, do you have an opinion here?

    Thanks again for testing the 3.11 beta! Reports like this help us improve.

  8. erlend-aasland commented on Jul 22, 2022

    @erlend-aasland
    erlend-aasland
    on Jul 22, 2022
    Contributor
    More actions

    I've already tried to look for a way to do these things because of keyword-only argument needs in another PR (#93823); I might actually be able to adopt that approach.

    FTR, this won't work. Arguments will still be passed incorrectly.

  9. erlend-aasland
    added a commit that references this issue on Jul 22, 2022

    [alt 1] pythongh-95132: partially revert 185ecdc

    479959f
  10. erlend-aasland commented on Jul 22, 2022

    @erlend-aasland
    erlend-aasland
    on Jul 22, 2022
    Contributor
    More actions

    I've partially reverted 185ecdc in #95146.

  11. erlend-aasland
    added a commit that references this issue on Jul 22, 2022

    [alt 2] pythongh-95132: use vectorcall

    b8ef03d
  12. erlend-aasland commented on Jul 22, 2022

    @erlend-aasland
    erlend-aasland
    on Jul 22, 2022
    Contributor
    More actions

    I've updated #95146 to use METH_FASTCALL and PyObject_Vectorcall.

  13. erlend-aasland
    moved this from TODO: Bugs to In Progress in sqlite3 issueson Jul 22, 2022
  14. erlend-aasland
    closed this as completedin #95146on Jul 23, 2022
  15. Repository owner moved this from In Progress to Done in sqlite3 issueson Jul 23, 2022
  16. erlend-aasland
    added 2 commits that reference this issue on Jul 23, 2022

    gh-95132: Correctly relay *args and **kwds from sqlite3.connect to fa…

    a3d4d15

    [3.11] pythongh-95132: Correctly relay *args and **kwds from sqlite3.…

    dbee099
  17. erlend-aasland commented on Jul 23, 2022

    @erlend-aasland
    erlend-aasland
    on Jul 23, 2022
    Contributor
    More actions

    Fixed in:

    • main: gh-95132: Correctly relay *args and **kwds from sqlite3.connect to factory #95146
    • 3.11: [3.11] gh-95132: Correctly relay *args and **kwds from sqlite3.connect to factory (GH-95146) #95158
  18. erlend-aasland
    added a commit that references this issue on Jul 23, 2022

    [3.11] gh-95132: Correctly relay *args and **kwds from sqlite3.connec…

    5d3f2fb
  19. vstinner commented on Aug 1, 2022

    @vstinner
    vstinner
    on Aug 1, 2022
    Member
    More actions

    Nice fix.

    Reacted by Erlend E. Aasland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @erlend-aasland
    erlend-aasland

Labels

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

Projects

  • sqlite3 issues
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.