Skip to content

fix: correctly separate disabled triggers in \d table output#161

Open
devadathanmb wants to merge 4 commits intodbcli:mainfrom
devadathanmb:fix/disabled-triggers-not-shown
Open

fix: correctly separate disabled triggers in \d table output#161
devadathanmb wants to merge 4 commits intodbcli:mainfrom
devadathanmb:fix/disabled-triggers-not-shown

Conversation

@devadathanmb
Copy link
Copy Markdown
Contributor

@devadathanmb devadathanmb commented Apr 11, 2026

Description

When \d table is used on a table with both enabled and disabled triggers, disabled triggers should appear under a separate Disabled triggers: section — consistent with how psql displays trigger information. Instead, all triggers were being lumped together under Triggers:, making it impossible to distinguish disabled triggers from enabled ones.

Two bugs in describe_one_table_details() caused this:

  1. The trigger rows were fetched by iterating directly over the live psycopg cursor, which is a forward-only stream. The code loops over 4 categories (enabled, disabled, always, replica) and re-iterates the cursor for each — but after the first category exhausted it, all subsequent passes saw no rows at all, so disabled triggers were never printed.
  2. The list_trigger flag that decides whether to print a row was reset once per category, not once per row. This meant that once any row in a pass set it to True, all subsequent rows in that pass were printed regardless of their actual state.

This change fixes both issues by materialising the cursor into a list with fetchall() before the loop, and resetting the flag per row.

I have run the full pgcli integration test suite locally with this patch in pgspecial to ensure that nothing breaks after this change.

Closes dbcli/pgcli#1519

Screenshots

psql (expected behaviour):

image

Before (In pgcli):

image

After (In pgcli):

image

Checklist

  • I've added this contribution to the changelog.rst.
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • Please squash merge this pull request (uncheck if you'd like us to merge as multiple commits)

@devadathanmb devadathanmb marked this pull request as ready for review April 11, 2026 15:03
Copilot AI review requested due to automatic review settings April 11, 2026 15:03
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes \d table output so disabled triggers are displayed under a separate Disabled triggers: section (matching psql), instead of being lumped into the enabled Triggers: section.

Changes:

  • Update trigger rendering in \d table details to iterate over a cached trigger result set, allowing proper per-category grouping.
  • Extend test DB fixtures with a table containing both enabled and disabled triggers, and add assertions covering the expected output split.
  • Update changelog and adjust existing expected object/function listings to account for the new fixtures.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pgspecial/dbcommands.py Fixes trigger categorization by re-iterating over fetched trigger rows per category (enabled/disabled/always/replica).
tests/dbutils.py Adds trigger-related fixtures (table, trigger function, enabled + disabled trigger).
tests/test_specials.py Updates listing expectations and adds a regression test verifying disabled triggers are shown under Disabled triggers:.
changelog.rst Documents the bug fix in the Unreleased section.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

\d table output does not distinguish disabled triggers

2 participants