Opened 8 years ago

Closed 8 years ago

Last modified 7 years ago

#27954 closed Cleanup/optimization (fixed)

Prevent PostgreSQL dbshell from exiting on CTRL-C

Reported by: Chris Sinchok Owned by: nobody
Component: Core (Management commands) Version: 1.10
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I love to use dbshell, but have a nitpick with how it works for Postgres. When I'm using psql normally, I use ctrl-c to cancel a query, or to just reset the prompt. However, when I CTRL-C within dbshell, it throws a KeyboardInterrupt.

Perhaps we could override the SIGINT handler directly before launching the psql subprocess, and restore the handler in the finally block? I will attach a sample patch.

Attachments (1)

dbshell-postgres-sigint.patch (1.2 KB ) - added by Chris Sinchok 8 years ago.
Sample fix

Download all attachments as: .zip

Change History (6)

by Chris Sinchok, 8 years ago

Sample fix

comment:1 by Tim Graham, 8 years ago

Component: Database layer (models, ORM)Core (Management commands)
Has patch: set
Needs tests: set
Summary: PostgreSQL dbshell exits on CTRL-CPrevent PostgreSQL dbshell from exiting on CTRL-C
Triage Stage: UnreviewedAccepted
Type: UncategorizedCleanup/optimization

I haven't look at the code in detail but solving the problem seems reasonable. Perhaps a test may be feasible with mocking?

comment:2 by Chris Sinchok, 8 years ago

I was able to mock out the behavior, so I wrote a failing test.

I've opened a PR here: https://github.com/django/django/pull/8248

comment:3 by Tim Graham, 8 years ago

Needs tests: unset

comment:4 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: assignedclosed

In 66150f7:

Fixed #27954 -- Allowed keyboard interrupt to abort queries in PostgreSQL dbshell.

Thanks Tim Martin for review.

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 7 years ago

In ad5f33e:

Refs #27954 -- Fixed typo in django/db/backends/postgresql/client.py comment.

Note: See TracTickets for help on using tickets.
Back to Top