mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-17 12:42:52 -06:00
Work around unapplied migrations when bootstrapping config
This commit is contained in:
parent
4cdc2601f5
commit
77bd26d17f
@ -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
|
||||||
revision = ConfigRevision.objects.last()
|
|
||||||
|
try:
|
||||||
|
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()
|
||||||
|
Loading…
Reference in New Issue
Block a user