Skip to content

Keep the prompt after database errors opening the editor - #1648

Open
ac1982 wants to merge 1 commit into
dbcli:mainfrom
ac1982:fix/editor-database-errors
Open

ac1982 wants to merge 1 commit into
dbcli:mainfrom
ac1982:fix/editor-database-errors

Conversation

@ac1982

@ac1982 ac1982 commented Oct 14, 2026

Copy link
Copy Markdown

Description

After BEGIN; SELECT 1 / 0;, running \ef function_name or \ev view_name raises InFailedSqlTransaction and exits pgcli. The interactive editor handler catches RuntimeError, but these metadata queries can also raise a psycopg DatabaseError.

Handle database errors at the existing editor error boundary, print the original message, and return to the prompt. The transaction remains aborted until the user chooses to roll it back. Both editor commands have regression tests using a real PostgreSQL connection, including recovery with ROLLBACK and a subsequent query.

Related to #1392. I reproduced the crash in an aborted transaction; BEGIN alone allowed function editing in my environment.

Validation on Linux / Python 3.12 / PostgreSQL 18.6:

  • Full pytest: 2,791 passed, 1 existing expected failure; the final added transaction-state assertion also passes the 105-test main module.
  • Behave: 33 scenarios passed, 9 skipped (including unavailable PgBouncer coverage), no failures.
  • Real terminal reproduction: before the fix pgcli exits with status 1; afterwards it returns to the prompt, accepts ROLLBACK and another query, and exits normally.
  • Ruff lint/format, repository pre-commit hooks, and changelog ReST checks pass.

The full upstream Python/PostgreSQL version matrix was not run locally. AI-assisted implementation and validation.

Checklist

  • I've added this contribution to the changelog.rst.
  • I've added my name to the AUTHORS file (or it's already there).
  • I installed pre-commit hooks (pip install pre-commit && pre-commit install).
  • I verified that my changes work as expected.
  • Please squash merge this pull request.

DiegoDAF added a commit to DiegoDAF/pgcli.daf that referenced this pull request Oct 14, 2026

This branch has not been deployed

No deployments
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