Skip to content

Improve /api/<table> schema display and surface table-description knowls - #7158

Open
roed-math wants to merge 5 commits into
LMFDB:mainfrom
roed-math:ai/t18-api-schema-knowls
Open

Improve /api/<table> schema display and surface table-description knowls#7158
roed-math wants to merge 5 commits into
LMFDB:mainfrom
roed-math:ai/t18-api-schema-knowls

Conversation

@roed-math

Copy link
Copy Markdown
Contributor

Closes #4811.
Closes #4812.

The per-table API pages (/api/<table>) get two related improvements.

For #4812, the schema table gains an Example column populated from a random row (db.<table>.random(projection=2)), with values quoted/truncated at 100 chars and [binary data] shown for bytea columns. The schema holder regains a shared schema-holder class and is now capped with max-height: 500px; overflow-y: auto in style.css, instead of the dead height: 300px block left behind by an earlier div-class rename, so small tables no longer render an oversized fixed-height scroll box while large tables still scroll.

For #4811, the tables.<name> description knowl is surfaced via KNOWL_INC above the schema (read-only for everyone, with an edit link for logged-in knowl editors) instead of being appended to the page title in parentheses.

Datapages share the same schema template but pass no example data, so they are unchanged apart from the holder styling; two new tests in test_api.py cover both the API-page Example column and the datapage's absence of it.

Note this branch will conflict lightly at merge time with the other open API PRs (ranges/null and raw-format) since they also edit api.py/collection.html/test_api.py in nearby but distinct regions.


Ported from roed-math#22, where the full write-up and comment history live.

🤖 Generated with Claude Code

roed314 and others added 5 commits July 19, 2026 11:15
…wls (LMFDB#4811, LMFDB#4812)

LMFDB#4812: give the schema table an Example column populated from a random
row (db.<table>.random(projection=2)), with values truncated at 100
chars, string reprs quoted, and "[binary data]" for bytea columns. The
holder div regains a shared `schema-holder` class and style.css caps it
with `max-height: 500px; overflow-y: auto` (via max-height so small
tables no longer get an oversized fixed-height scroll box) instead of the
dead `height: 300px` block, which no longer matched after the div class
was renamed. The duplicate `id="schema-table"` becomes a class.

LMFDB#4811: stop appending the table description to the page title and instead
surface the `tables.<name>` knowl via KNOWL_INC in collection.html
(read-only content for everyone, edit link for logged-in knowl editors).

Verified: sage -python -m pytest lmfdb/api/test_api.py (8 passed, incl.
two new tests); pyflakes clean on api.py and test_api.py; test-client
render of nf_fields, ec_curvedata, mf_hecke_traces, lat_lattices,
gps_groups and char_dirichlet shows a populated Example column, the
description knowl above the schema, and a title without the parenthetical;
datapages still render with no Example column; /style.css serves 200.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…DB#4812)

The /api/<table> schema Example column was sampled with
coll.random(projection=2).  Switch to projection=3, the same full
mask (id + all search + all extra columns) the datapage query already
uses, so the Example column is sampled consistently and every row shown
in the schema table can be populated.

Strengthen test_api_schema_display: instead of only asserting that
schema-example cells exist, assert that the Example cell for the
never-null search column nf_fields.degree carries an actual value, so a
future change that blanks search-column examples is caught.

Verified: sage -python -m pytest lmfdb/api/test_api.py -> 8 passed;
pyflakes clean; test-client renders of /api/nf_fields,
/api/ec_curvedata and /api/maass_newforms show nonblank Example cells
for search columns (degree, conductor, conrey_index) and the extra
column (maass_newforms.coefficients).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…a-knowls

# Conflicts:
#	lmfdb/api/api.py
#	lmfdb/api/templates/apischema.html
…MFDB#4811)

The tables.<table> knowl was included on /api/<table> without a heading,
so the page lost the description text that used to sit in its title
without gaining the header-backed, editable knowl the issue asks for.
Three things stood in the way, all fixed here.

Knowl.__init__ overwrote every type 2 title with a generated string, so
a custom title saved on a tables.<table> knowl was discarded on load.
Generated titles are what we want for columns.<table>.<column>, so keep
those; for a table description, use the stored title and only fall back
to "Table <table>" when the record has none.  The defunct marker is
still appended, but not a second time when a title saved while the table
was defunct already carries it.

knowl-edit.html showed every type 2 title as read-only text plus a
hidden input, and offered a "Postgres column type" row that is None for
a table.  Split the two cases apart by source (a column description
records its table, a table description has none): a table description
now gets a labelled, editable title input and no column type row, while
a column description is unchanged.

KNOWL_INC emitted no heading when called without an explicit title, with
the knowl's own title left commented out.  Add an opt-in show_title
argument that renders it, which leaves the other 42 call sites alone and
takes the title from the same Knowl object as the content, so the two
cannot come from different versions.  collection.html now calls it with
htag='h2', show_title=True.  A missing knowl is untouched: anonymous
users still see nothing rather than an empty heading, and authenticated
users still get the create link.

Tests: test_api_table_description asserts the heading is present, is
derived from the knowl rather than hard coded, and precedes both the
description and the schema controls; DescriptionKnowlTest covers the
model (custom title kept, generated fallback, defunct marker not
doubled, column titles still generated) and renders knowl-edit.html for
both kinds to check the editable/read-only split and the column type
row.  All four fail on the previous head.  Also fixed the stale
assertion in test_api_schema_display, which looked for a <title> prefix
that never matches.

Verified: sage -python -m pytest lmfdb/api/test_api.py
lmfdb/tests/test_dynamic_knowls.py -> 22 passed; pyflakes clean; a
test-client render of /api/artin_old2new_labels (a table with no
description knowl) shows an empty description div and no bogus heading.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
)

Making the title editable exposed a way to lose it.  Whenever a table
description title becomes something an editor chose rather than a string
we regenerate, every writer has to carry it, and set_table_description
did not: it built its Knowl from content and defines alone, so the new
constructor supplied the "Table <table>" fallback and KnowlBackend.save
persisted that as the title.  most_recent merges authors, not the title.

The effect was that db.<table>.description("...") -- a content-only
update, typically from a data-loading script -- would silently reset a
title an editor had set.  Fetch the old record before building the data
dict, which set_table_description already did for the authors, and pass
its title through.  A table description with no record yet still gets
the generated fallback.

set_column_description needs no such change: column titles are always
regenerated from the id, so there is nothing there to lose.

Tests: test_content_update_keeps_table_title mocks out the database
write (get_knowl, save and db.login are patched, so nothing touches the
read-only connection) and asserts the knowl handed to save keeps the old
title while taking the new content; test_content_update_generates_
missing_table_title covers the no-previous-record case.  The first fails
on ee561c5 with 'Table nf_fields' == 'Number field data'.

Verified: sage -python -m pytest -q lmfdb/tests/test_dynamic_knowls.py
lmfdb/api/test_api.py -> 25 passed; pyflakes clean.

Co-Authored-By: Claude Opus 5 <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.

Improvements to schema display Make table description a knowl

2 participants