Work around unapplied migrations when bootstrapping config

This commit is contained in:
jeremystretch 2021-10-26 17:28:39 -04:00
parent 4cdc2601f5
commit 77bd26d17f

View File

@ -3,6 +3,7 @@ import threading
from django.conf import settings from django.conf import settings
from django.core.cache import cache from django.core.cache import cache
from django.db.utils import DatabaseError
from .parameters import PARAMS from .parameters import PARAMS
@ -73,7 +74,18 @@ class Config:
def _populate_from_db(self): def _populate_from_db(self):
"""Cache data from latest ConfigRevision, then populate from cache""" """Cache data from latest ConfigRevision, then populate from cache"""
from extras.models import ConfigRevision from extras.models import ConfigRevision
try:
revision = ConfigRevision.objects.last() revision = ConfigRevision.objects.last()
except DatabaseError:
# The database may not be available yet (e.g. when running a management command)
logger.warning(f"Skipping config initialization (database unavailable)")
return
if revision is None:
logger.debug("No previous configuration found in database; proceeding with default values")
return
revision.cache() revision.cache()
logger.debug("Filled cache with data from latest ConfigRevision") logger.debug("Filled cache with data from latest ConfigRevision")
self._populate_from_cache() self._populate_from_cache()