From 196a2deb6f18e41ded4ddff78ee2c228516b3c16 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 30 Dec 2024 22:24:25 -0800 Subject: [PATCH] app: Allow apps to instantiate without Django initialization - When tags are added to Menu and Shortcut components, we will need to access info.tags which tries to extract the original string from lazy proxy. This requires Django initialized. When privileged process tries to initialize the app without initializing Django, this leads to an error. Fix this by extracing the original string from a lazy proxy a hacky way. Tests: - Running diagnostics does not show errors with Django initialization in checks for configuration links. Signed-off-by: Sunil Mohan Adapa Reviewed-by: Joseph Nuthalapati --- plinth/app.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/plinth/app.py b/plinth/app.py index b14dd34ff..3313a1b8b 100644 --- a/plinth/app.py +++ b/plinth/app.py @@ -532,9 +532,19 @@ class Info(FollowerComponent): These can only be retrieved after Django has been configured. """ # Store untranslated original strings instead of proxy objects + from django.core.exceptions import ImproperlyConfigured + from django.utils.functional import Promise from django.utils.translation import override - with override(language=None): - return [str(tag) for tag in self._tags] + try: + with override(language=None): + return [str(tag) for tag in self._tags] + except ImproperlyConfigured: + # Hack to allow apps to be instantiated without Django + # initialization as required by privileged process. + return [ + tag._proxy____args[0] if isinstance(tag, Promise) else tag + for tag in self._tags + ] @classmethod def list_tags(self) -> list[str]: