sqlite-utils icon indicating copy to clipboard operation
sqlite-utils copied to clipboard

Whether or not a table remembers or detects its primary key is confusing and messy

Open simonw opened this issue 5 months ago • 4 comments

Creating a table should stash its settings in self._defaults?

I bodged around this in:

  • #653

See this snippet of suggestion from Gemini 2.5 Flash: https://gist.github.com/simonw/d867a1791b40b3a5fbfb66b75417c0a3#response-2

But really what should happen is that this code here: https://github.com/simonw/sqlite-utils/blob/72f6c820f683ba4bd312679f5302d92e75254a53/sqlite_utils/db.py#L1695-L1713

Should record ALL of the interesting things on self._defaults.

This matters because if you do table = db.table("name_of_table") (where that table does not exist yet) and then call table.insert({...}, pk="id", ...) the table gets created but self._defaults is not updated, so future methods on that table don't know what the settings are.

This differs from if you do:

table = db.insert({...}, pk="id")

Because in that case the returned table DOES know it settings (I think, maybe because it can introspect them? Not 100% sure.)

simonw avatar May 08 '25 23:05 simonw