Skip to content

Insert API tests for primary key edge cases, plus two fixes - #3081

Merged
simonw merged 1 commit into
mainfrom
insert-api-pk-tests
Nov 22, 2026
Merged

simonw merged 1 commit into
mainfrom
insert-api-pk-tests

Conversation

@simonw

@simonw simonw commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Refs:

Claude Code

Adds test_insert_primary_key_edge_cases, a parametrized test that runs a sequence of /-/insert requests against each kind of table and checks the status, the returned rows and the final table contents:

  • Integer primary key: explicit value, then automatic values continue from it
  • Text primary key
  • Compound primary key
  • No primary key (rowid only): with and without an explicit rowid
  • WITHOUT ROWID, with single and compound primary keys

Each covers "row", "rows" with "return": true, primary key conflicts, and "ignore" / "replace" where they work.

Bugs fixed

Writing the tests turned up two bugs, both fixed in this PR:

  1. WITHOUT ROWID tables could not return inserted rows. Any insert using "row" (which always returns) or "return": true failed with no such column: rowid and inserted nothing, because rows were fetched back by rowid. These tables now fetch rows back by primary key.
  2. Rows returned from a table with no primary key did not include the rowid, so a client could not tell which row it had created. They now include it, matching the upsert API and the table JSON. This is an addition to the response and is noted in the JSON API docs.

Found but not fixed

I used "Refs" not "Closes" because of the first of those.

🤖 Generated with Claude Code

Tests cover integer, text and compound primary keys, rowid-only tables
and WITHOUT ROWID tables. Writing them turned up two bugs, fixed here:

- Inserting with "row" or "return": true into a WITHOUT ROWID table
  failed with "no such column: rowid"
- Rows returned from a table with no primary key did not include the
  rowid, unlike the upsert API

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@simonw simonw added this to the Datasette 1.0 stable milestone Nov 16, 2026
@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 16 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (6c6120c) to head (aef0911).

Files with missing lines Patch % Lines
datasette/views/table.py 0.00% 16 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main   #3081   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         79      79           
  Lines      13974   13988   +14     
=====================================
- Misses     13974   13988   +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@simonw
simonw merged commit 8c91973 into main Nov 22, 2026
15 checks passed
@simonw
simonw deleted the insert-api-pk-tests branch November 22, 2026 23:25
simonw added a commit that referenced this pull request Nov 23, 2026
…upgrade guide sections

Release notes for the null, empty string and binary primary key work
(#3112), the SpatiaLite KNN count fix (#1611), the insert API fixes
(#3081) and the first column facet on views (#2810), which landed
without any. The summary paragraph now mentions primary keys and view
filters.

New upgrade guide sections for datasette.urls.modify(), keyword-only
arguments, format_bytes(), TestClient and primary key values, linked
from their changelog entries.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant