diff --git a/datasette/views/table.py b/datasette/views/table.py index 9798174e..22dca7e0 100644 --- a/datasette/views/table.py +++ b/datasette/views/table.py @@ -671,7 +671,7 @@ async def display_columns_and_rows( } pks = await db.primary_keys(table_name) pks_for_display = pks - if not pks_for_display: + if not pks_for_display and not await db.view_exists(table_name): pks_for_display = ["rowid"] label_column = None if link_column: diff --git a/docs/changelog.rst b/docs/changelog.rst index 3c4a214d..4d0f719e 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -26,6 +26,7 @@ Datasette plugins can now use **background tasks** to run code independent of th Bug fixes ~~~~~~~~~ +- The :ref:`render_cell() ` plugin hook now receives an empty ``pks`` list when rendering SQL views in HTML, matching the JSON ``?_extra=render_cell`` behavior. (:issue:`2639`) - Numeric comparison filters now correctly handle decimal values, negative numbers and scientific notation when filtering computed columns and SQL views. Thanks, `Rami Abdelrazzaq `__. (:issue:`1681`, :pr:`2876`) - Fixed CSV streaming with ``?_stream=on`` on SQL views repeating the second page of results until the CSV size limit was reached. Thanks, `Ankita Advitot `__. (:issue:`2902`, :pr:`2903`) diff --git a/docs/plugin_hooks.rst b/docs/plugin_hooks.rst index ae49fd9b..8a9ce5da 100644 --- a/docs/plugin_hooks.rst +++ b/docs/plugin_hooks.rst @@ -495,10 +495,10 @@ Lets you customize the display of values within table cells in the HTML table vi The name of the column being rendered ``table`` - string or None - The name of the table - or ``None`` if this is a custom SQL query + The name of the table or view - or ``None`` if this is a custom SQL query ``pks`` - list of strings - The primary key column names for the table being rendered. For tables without an explicitly defined primary key, this will be ``["rowid"]``. For custom SQL queries and views (where ``table`` is ``None``), this will be an empty list ``[]``. + The primary key column names for the table being rendered. For tables without an explicitly defined primary key, this will be ``["rowid"]``. For custom SQL queries and views, this will be an empty list ``[]``. ``database`` - string The name of the database