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 <sunil@medhas.org>
Reviewed-by: Joseph Nuthalapati <njoseph@riseup.net>
This commit is contained in:
Sunil Mohan Adapa 2024-12-30 22:24:25 -08:00 committed by Joseph Nuthalapati
parent 67cef398e1
commit 196a2deb6f
No known key found for this signature in database
GPG Key ID: 5398F00A2FA43C35

View File

@ -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]: