Title: SQLite rowcount is corrupted when combining UPDATE RETURNING w/ table that is dropped and recreated · Issue #93421 · python/cpython · GitHub
Open Graph Title: SQLite rowcount is corrupted when combining UPDATE RETURNING w/ table that is dropped and recreated · Issue #93421 · python/cpython
X Title: SQLite rowcount is corrupted when combining UPDATE RETURNING w/ table that is dropped and recreated · Issue #93421 · python/cpython
Description: version info: $ python Python 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import sqlite3 >>> sqlite3.sqlite_version '...
Open Graph Description: version info: $ python Python 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> imp...
X Description: version info: $ python Python 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux Type "help", "copyright", "credits" or "lic...
Opengraph URL: https://github.com/python/cpython/issues/93421
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SQLite rowcount is corrupted when combining UPDATE RETURNING w/ table that is dropped and recreated ","articleBody":"version info:\r\n\r\n```\r\n$ python\r\nPython 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux\r\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\r\n\u003e\u003e\u003e import sqlite3\r\n\u003e\u003e\u003e sqlite3.sqlite_version\r\n'3.36.0'\r\n```\r\n\r\n\r\nwe 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:\r\n\r\n```py\r\nimport os\r\nimport sqlite3\r\n\r\n\r\n\r\ndef go():\r\n \"\"\"function creates a new table, runs INSERT/UPDATE, drops table,\r\n commits connection.\r\n\r\n \"\"\"\r\n\r\n # create table\r\n cursor = conn.cursor()\r\n cursor.execute(\r\n \"\"\"CREATE TABLE some_table (\r\n id INTEGER NOT NULL,\r\n value VARCHAR(40) NOT NULL,\r\n PRIMARY KEY (id)\r\n )\r\n \"\"\"\r\n )\r\n cursor.close()\r\n conn.commit()\r\n\r\n # run operation\r\n cursor = conn.cursor()\r\n cursor.execute(\r\n \"INSERT INTO some_table (id, value) VALUES (1, 'v1')\"\r\n )\r\n ident = 1\r\n\r\n cursor.execute(\r\n \"UPDATE some_table SET value='v2' \"\r\n \"WHERE id=? RETURNING id\",\r\n (ident,),\r\n )\r\n new_ident = cursor.fetchone()[0]\r\n assert ident == new_ident\r\n assert cursor.rowcount == 1, cursor.rowcount\r\n cursor.close()\r\n\r\n # drop table\r\n cursor = conn.cursor()\r\n cursor.execute(\"DROP TABLE some_table\")\r\n cursor.close()\r\n\r\n conn.commit()\r\n\r\nif os.path.exists(\"file.db\"):\r\n os.unlink(\"file.db\")\r\n\r\n# passes\r\nconn = sqlite3.connect(\"file.db\")\r\ngo()\r\n\r\n# run again w/ new connection (same DB), passes\r\nconn = sqlite3.connect(\"file.db\")\r\ngo()\r\n\r\nprint(\"FAILURE NOW OCCURS\")\r\n# run again w/ same connection, fails\r\ngo()\r\n```\r\n\r\non the third run, where we ran the \"test\" on the same connection twice, it fails:\r\n\r\n```\r\n$ python test3.py \r\nFAILURE NOW OCCURS\r\nTraceback (most recent call last):\r\n File \"/home/classic/dev/sqlalchemy/test3.py\", line 62, in \u003cmodule\u003e\r\n go()\r\n File \"/home/classic/dev/sqlalchemy/test3.py\", line 39, in go\r\n assert cursor.rowcount == 1, cursor.rowcount\r\nAssertionError: 0\r\n```\r\n\r\nit would appear there's some internal caching of table state that needs to be cleared.","author":{"url":"https://github.com/zzzeek","@type":"Person","name":"zzzeek"},"datePublished":"2022-06-01T22:50:28.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":26},"url":"https://github.com/93421/cpython/issues/93421"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:32db20d6-02c0-c2f6-c442-decf49cbae44 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A26C:280F84:AFA149:F4503A:696A33CA |
| html-safe-nonce | dbce924823c23a743dafd37badd4fb0127ada8f8a0eb122f18213337124eb12f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMjZDOjI4MEY4NDpBRkExNDk6RjQ1MDNBOjY5NkEzM0NBIiwidmlzaXRvcl9pZCI6IjI3NjE5Mjc5MjQ2MDY3MTA3MzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 10b7e05cdfd4cd36a5ea1473a5886db9f5acdd5c499142ee522ea545dfc5c1b1 |
| hovercard-subject-tag | issue:1257220178 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/93421/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b11e8092f78a10304babffd9b527706f3e5bd6789fa118d1a21f08a6415f2e0/python/cpython/issues/93421 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b11e8092f78a10304babffd9b527706f3e5bd6789fa118d1a21f08a6415f2e0/python/cpython/issues/93421 |
| og:image:alt | version info: $ python Python 3.10.0 (default, Nov 5 2021, 17:23:47) [GCC 11.2.1 20210728 (Red Hat 11.2.1-1)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> imp... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zzzeek |
| hostname | github.com |
| expected-hostname | github.com |
| None | 321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7a9163cefd1ea4bd06f8eb7c082f43e4e53f626f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width