Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

SQLite rowcount is corrupted when combining UPDATE RETURNING w/ table that is dropped and recreated #93421

Closed
Assignees
erlend-aasland
Labels
3.11only security fixes3.12only security fixestopic-sqlite3type-bugAn unexpected behavior, bug, or error
@zzzeek

Description

@zzzeek

version info:

$ pythonPython 3.10.0 (default, Nov  5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linuxType "help", "copyright", "credits" or "license" for more information.>>> import sqlite3>>> sqlite3.sqlite_version'3.36.0'

we have a test suite that creates a table, runs some SQL, then drops it. if multiple tests run that each perform this task, if the same SQLite connection is used, rowcount starts returning "0". Seems to also require RETURNING to be used. Full demonstration:

importosimportsqlite3defgo():"""function creates a new table, runs INSERT/UPDATE, drops table,    commits connection.    """# create tablecursor=conn.cursor()cursor.execute("""CREATE TABLE some_table (        id INTEGER NOT NULL,        value VARCHAR(40) NOT NULL,        PRIMARY KEY (id)    )    """    )cursor.close()conn.commit()# run operationcursor=conn.cursor()cursor.execute("INSERT INTO some_table (id, value) VALUES (1, 'v1')"    )ident=1cursor.execute("UPDATE some_table SET value='v2' ""WHERE id=? RETURNING id",        (ident,),    )new_ident=cursor.fetchone()[0]assertident==new_identassertcursor.rowcount==1,cursor.rowcountcursor.close()# drop tablecursor=conn.cursor()cursor.execute("DROP TABLE some_table")cursor.close()conn.commit()ifos.path.exists("file.db"):os.unlink("file.db")# passesconn=sqlite3.connect("file.db")go()# run again w/ new connection (same DB), passesconn=sqlite3.connect("file.db")go()print("FAILURE NOW OCCURS")# run again w/ same connection, failsgo()

on the third run, where we ran the "test" on the same connection twice, it fails:

$  python test3.py FAILURE NOW OCCURSTraceback (most recent call last):  File "/home/classic/dev/sqlalchemy/test3.py", line 62, in <module>    go()  File "/home/classic/dev/sqlalchemy/test3.py", line 39, in go    assert cursor.rowcount == 1, cursor.rowcountAssertionError: 0

it would appear there's some internal caching of table state that needs to be cleared.

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixestopic-sqlite3type-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp