Repository navigation
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e1aa034584
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| SELECT {table_name}, (SELECT count(*) FROM {table}) | ||
| WHERE changes() = 0; |
There was a problem hiding this comment.
Make missing-row recovery safe for nested inserts
If an empty table's _counts row is removed and an AFTER INSERT trigger created after enable_counts() inserts a second row into the same table, this recount runs inside the nested insertion while both rows are already visible. It seeds 2, then the still-pending outer count trigger adds another 1, leaving table.count == 3 for two rows. The previous triggers returned 2 for this same sequence, so the recovery path introduces persistent cache corruption for nested writes. Account for pending outer trigger updates rather than combining a full recount with their deltas.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed. With the cache row removed, I reproduced a cached count of 3 for two rows. In d61cfc2 the triggers only update existing cache entries. When an entry is missing, table.count uses its live query until reset_counts() or enable_counts() restores the entry, so pending trigger frames cannot apply a delta to a partial recount. The regression test covers nested inserts and deletes with the count triggers created in either order and checks that subsequent updates stay in sync after a reset.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d61cfc2a76
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| statements.append(textwrap.dedent(f""" | ||
| CREATE TRIGGER IF NOT EXISTS {trigger} AFTER {event} ON {table} |
There was a problem hiding this comment.
Dedent the SQL template before interpolating table names
For a table name containing a newline followed by spaces, such as items\n archive, expanding the f-string before calling dedent() removes whitespace inside the quoted identifiers and string literals, changing the name to items\narchive. I reproduced enable_counts() raising OperationalError: no such table for this input; if the dedented name belongs to another table, the triggers are instead installed there and the original table's cached count remains stale. The previous implementation dedented the template before formatting it, preserving the supplied names. Keep interpolation after dedenting.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Confirmed on the previous head: enable_counts() failed for a table named items\n archive. In 537f74d the trigger statement is built without dedenting its substituted identifiers or literals. The regression test exercises inserts, duplicate ignores and deletes using that name. I also checked pairs of coexisting table names that differed only in whitespace; each maintained its own count. Both full-suite runs passed with standard transactions and autocommit.
Fixes #1001.
SQLite applies the conflict policy of an outer
INSERT OR IGNOREto the insert inside the count trigger. Once a row exists in_counts, this can silently skip the counter update even though the source row was inserted.The triggers now update the existing count directly. If someone deletes the cache row,
table.countfalls back to a live count untilreset_counts()orenable_counts()restores it. A trigger cannot safely rebuild the cache fromcount(*)during nested writes because other trigger updates may still be pending. The regression tests exercise nested inserts and deletes with the count triggers installed in either order. The trigger SQL also works on SQLite 3.23.1.For databases with existing count triggers, running
enable-countsagain refreshes the cached value and upgrades the definitions written by earlier sqlite-utils releases. Only recognized legacy definitions are replaced. The tests cover quote styles used by 3.x and 4.x, including the mixed quoting SQLite writes after renaming a 3.x table and renaming it back. They also check that unrelated user triggers, including same-name TEMP triggers, are preserved.With standard transactions and with autocommit, each full-suite run passed 1,639 tests with 17 optional-dependency skips. The tests also exercise table names with quotes and with an indented line break. I reproduced the stale count on a database created by the unmodified code, then verified that re-enabling counts and continuing the import kept the persisted and actual counts in sync.
Prepared and tested by OpenAI Codex on behalf of @anlonely.