Repository navigation
One Column class: db.table_column_details() returns datasette.Column - #3101
Merged
Merged
Conversation
…loses #3100 datasette.utils.Column, a named tuple, is removed. datasette.Column gains the notnull, default_value, pk_position and hidden attributes it carried, and db.table_column_details() returns a Columns object of them. - is_pk is now pk_position, cid is dropped, and type is None instead of "" for a column declared without a type - Column.table, Column.foreign_key and the ForeignKey class are removed. Nothing in core read them, and filling them in for every call would have cost an extra query each time - db.describe_columns(), which was never released, is removed. The table and row views attach the columns from table_column_details() instead - The catalog_columns table and all JSON output are unchanged Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3101 +/- ##
=====================================
Coverage 0.00% 0.00%
=====================================
Files 81 81
Lines 14516 14512 -4
=====================================
+ Misses 14516 14512 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
SQLite 3.25 reports a declared type exactly as it was written, so a column declared as text came back as 'text' where the test expected 'TEXT'. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Owner
Author
|
I was unconvinced by this:
The And |
simonw
commented
Nov 22, 2026
Column.hidden was the integer from PRAGMA table_xinfo: 1 for a hidden column of a virtual table, 2 or 3 for a generated column. It is now True only for a hidden virtual table column, and Column.generated is "virtual", "stored" or None. The column_details JSON extra and the catalog_columns table still report SQLite's integer, rebuilt by table_xinfo_hidden(). Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
simonw
added a commit
that referenced
this pull request
Nov 23, 2026
Refs #1048, #1342, #1479, #1553, #1611, #1627, #1630, #1671, #1674, #1822, #1841, #1873, #1914, #1919, #1973, #2045, #2073, #2145, #2253, #2356, #2419, #2713, #2805, #2807, #2810, #2826, #2942, #2967, #3070, #3074, #3075, #3078, #3079, #3081, #3082, #3083, #3084, #3085, #3087, #3088, #3089, #3090, #3091, #3092, #3093, #3097, #3098, #3099, #3100, #3101, #3102, #3103, #3104, #3105, #3106, #3107, #3108, #3109, #3111, #3112, #3113, #3115
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes:
datasette.utils.Columnwithdatasette.Column#3100There were two classes called
Column:datasette.Column, describing a column of a row, and thedatasette.utils.Columnnamed tuple returned bydb.table_column_details(). This removes the named tuple and usesdatasette.Columnfor both.Claude Fable 5.2 High
What changed
datasette.Columngains the attributes the named tuple carried:notnull,default_value,pk_positionandhidden, plus a newgenerated. They areNonefor the columns of an arbitrary SQL query, the same astype.hiddenis a boolean,Trueonly for a hidden column of a virtual table.generatedis"virtual"or"stored"for a generated column andNoneotherwise. The named tuple had both in onehiddeninteger, using the numbers from SQLite'sPRAGMA table_xinfo(1 for hidden, 2 or 3 for generated).db.table_column_details(table)anddatasette.utils.table_column_details(conn, table)return aColumnsobject ofdatasette.Column.columns["name"]looks a column up by name.datasette.utils.Columnis deleted.db.describe_columns()is deleted. It was added in datasette.Row replaces sqlite3.Row and CustomRow #3099 and never released. The table and row views now attach the columns fromtable_column_details()to their rows.Column.table,Column.foreign_keyand theForeignKeyclass are deleted. They were also added in datasette.Row replaces sqlite3.Row and CustomRow #3099 and nothing in core read them. Foreign keys are still available fromdb.foreign_keys_for_table().Backwards incompatible
For code that uses
db.table_column_details():is_pkis nowpk_position. It always held the position in the primary key, not a boolean.typeisNonefor a column declared without a type. It was an empty string.hiddenis a boolean and no longer true for generated columns. Code that usedif column.hiddento skip columns that cannot be written to needsif column.hidden or column.generated.cidis gone. It was the position of the column in the list.Columnsobject, not a list. It can be looped over and indexed the same way.name,type,notnullanddefault_valueare otherwise read exactly as before.docs/upgrade_guide.mdhas a new section with before and after code.How this differs from the spec posted on the issue
That spec was written before #3099 was finished and is out of date in places. This PR follows a simpler version:
typestays a plain string. The spec assumed aDatabaseTypeclass, which was removed before datasette.Row replaces sqlite3.Row and CustomRow #3099 merged.generatedis a string,"virtual"or"stored". The spec proposed a boolean. The string is needed because thecolumn_detailsJSON extra documents different values for the two kinds, and that output is unchanged here.is_pkis renamed. The spec also renameddefault_valuetodefault.table_column_details()does not look up foreign keys. The spec had it run an extraPRAGMA foreign_key_liston every call, and a table page calls it 5 to 10 times. DroppingColumn.foreign_keyavoids that.Unchanged output
catalog_columnstable in the internal database keeps its schema and contents, includingcidandis_pk.column_detailsJSON extra still returnstypeas""for an untyped column, and bothis_pkandpk_position.hiddenas SQLite's integer, 0 to 3. It is rebuilt from the two new attributes bydatasette.utils.table_xinfo_hidden(column).To check this I captured, before and after the change, everything derived from column details for all 37 tables and views in the fixtures database plus three extra tables (generated columns, a compound primary key in non-table order, and a table with no primary key): the
column_details,columns,display_columns,primary_keysandcolumn_typesJSON extras, the table page's template context (including the insert, edit and alter form data), every row ofcatalog_columns, and the results ofdb.primary_keys()anddb.table_columns(). All 150 outputs are identical.Performance
Per call, on a 10-column table, best of three runs against
main:table_column_details()detect_primary_keys()table_columns()table_column_details()is slower because a frozen dataclass costs more to construct than a named tuple, and it now has one more attribute to fill in.detect_primary_keys()andtable_columns()now read thePRAGMArows directly without buildingColumnobjects, so they are faster than before. I did not measure whole pages for this PR.Testing
datasette/rows.pypassesmypy --strict.db.table_column_details(), a compound primary key whose order differs from the table's column order, virtual and stored generated columns, the hidden columns of an FTS5 table, and how the columns of a row are derived for the implicitrowidand for names that are not columns of the table.table_xinfois unavailable and a fallback path is used. The CI job for 3.25 covers it.🤖 Generated with Claude Code