From 5262d89505df664654d663b37976a18c234c9a01 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 22 Nov 2022 20:30:00 +0100 Subject: [PATCH] core: fix tab-complete in shell Signed-off-by: Jens Langhammer --- authentik/core/management/commands/shell.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/authentik/core/management/commands/shell.py b/authentik/core/management/commands/shell.py index ef26770e3..a348fd476 100644 --- a/authentik/core/management/commands/shell.py +++ b/authentik/core/management/commands/shell.py @@ -1,6 +1,8 @@ """authentik shell command""" import code import platform +import sys +import traceback from django.apps import apps from django.core.management.base import BaseCommand @@ -88,7 +90,21 @@ class Command(BaseCommand): # pylint: disable=exec-used exec(options["command"], namespace) # nosec # noqa return - + try: + hook = sys.__interactivehook__ + except AttributeError: + # Match the behavior of the cpython shell where a missing + # sys.__interactivehook__ is ignored. + pass + else: + try: + hook() + except Exception: + # Match the behavior of the cpython shell where an error in + # sys.__interactivehook__ prints a warning and the exception + # and continues. + print("Failed calling sys.__interactivehook__") + traceback.print_exc() # Try to enable tab-complete try: import readline