diff options
| author | Aman Sharma <210100011@iitb.ac.in> | 2024-12-17 14:00:33 +0530 |
|---|---|---|
| committer | Sarah Boyce <42296566+sarahboyce@users.noreply.github.com> | 2024-12-19 11:33:18 +0100 |
| commit | f05edb2b43c347d4929efd52c8e2b4e08839f542 (patch) | |
| tree | 0765099eb2781e4bca8efd646b44683cea39b89a /django | |
| parent | 3ee4c6a27ad520d4ecc3cded260d47cbccafb144 (diff) | |
Fixed #36016 -- Prevented traceback when quitting makemigrations with Ctrl-C.
Diffstat (limited to 'django')
| -rw-r--r-- | django/db/migrations/questioner.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/django/db/migrations/questioner.py b/django/db/migrations/questioner.py index 2e61195581..445d4410e6 100644 --- a/django/db/migrations/questioner.py +++ b/django/db/migrations/questioner.py @@ -111,17 +111,19 @@ class InteractiveMigrationQuestioner(MigrationQuestioner): for i, choice in enumerate(choices): self.prompt_output.write(" %s) %s" % (i + 1, choice)) self.prompt_output.write("Select an option: ", ending="") - result = input() while True: try: + result = input() value = int(result) except ValueError: pass + except KeyboardInterrupt: + self.prompt_output.write("\nCancelled.") + sys.exit(1) else: if 0 < value <= len(choices): return value self.prompt_output.write("Please select a valid option: ", ending="") - result = input() def _ask_default(self, default=""): """ @@ -148,7 +150,11 @@ class InteractiveMigrationQuestioner(MigrationQuestioner): else: prompt = ">>> " self.prompt_output.write(prompt, ending="") - code = input() + try: + code = input() + except KeyboardInterrupt: + self.prompt_output.write("\nCancelled.") + sys.exit(1) if not code and default: code = default if not code: |
