Skip to content

Apply render_cell plugin hook to primary key columns#2652

Open
westurner wants to merge 1 commit intosimonw:mainfrom
westurner:render_cell_on_pk_cols
Open

Apply render_cell plugin hook to primary key columns#2652
westurner wants to merge 1 commit intosimonw:mainfrom
westurner:render_cell_on_pk_cols

Conversation

@westurner
Copy link
Copy Markdown

@westurner westurner commented Mar 3, 2026

This update modifies the table view to execute the render_cell plugin hook against simple (single) primary key (or "Link") columns. Instead of always generating a default HTML anchor link pointing to the row view, Datasette now checks if any plugin returns a custom display value. If a custom rendering is provided, it is used; otherwise, it safely falls back to the default <a href="..."> behavior.

Key Changes & Optimizations:

  • Feature: Executes render_cell hooks for simple primary keys in display_columns_and_rows, safely resolving pk_value from the row.
  • Performance: Pre-computes has_single_pk, pk_index, and has_render_cell_hooks outside of the O(N) row loop to eliminate redundant operations.
  • Performance: Completely skips hook evaluation if no plugins are registered to listen to render_cell.
  • Refactor: Streamlines row cell appending by using an inline A if A is not None else B fallback, which prevents duplicate dictionary initializations and safely handles intentional empty strings ("") returned by plugins.
  • Compatibility: Passes pks=pks_for_display to the hook call to satisfy upstream API requirements.

Assisted By: Gemini 3.1 Pro


📚 Documentation preview 📚: https://datasette--2652.org.readthedocs.build/en/2652/

This update modifies the table view to execute the `render_cell` plugin
hook against simple (single) primary key (or "Link") columns. Instead of
always generating a default HTML anchor link pointing to the row view,
Datasette now checks if any plugin returns a custom display value. If a
custom rendering is provided, it is used; otherwise, it safely falls
back to the default `<a href="...">` behavior.

Key Changes & Optimizations:
- Feature: Executes `render_cell` hooks for simple primary keys in
  `display_columns_and_rows`, safely resolving `pk_value` from the row.
- Performance: Pre-computes `has_single_pk`, `pk_index`, and
  `has_render_cell_hooks` outside of the O(N) row loop to eliminate
  redundant operations.
- Performance: Completely skips hook evaluation if no plugins are
  registered to listen to `render_cell`.
- Refactor: Streamlines row cell appending by using an inline
  `A if A is not None else B` fallback, which prevents duplicate
  dictionary initializations and safely handles intentional empty
  strings (`""`) returned by plugins.
- Compatibility: Passes `pks=pks_for_display` to the hook call
  to satisfy upstream API requirements.

Assisted By: Gemini 3.1 Pro
@westurner
Copy link
Copy Markdown
Author

From https://github.com/pulp for example:

All contributors must indicate in the commit message of their contribution if they used AI to create them and the contributor is fully responsible for the content that they submit.

This can be a label such as Assisted By: or Generated by: based on what was used.

So I added "Assisted By:". I would say this one was more of a pair coding with LLMs than a vibe coding. I ran the tests a number of times locally. I'm not sure why I have 15 local test failures before and after this PR. Does the Actions build run the tests with coverage?

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