mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-16 12:12:53 -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.core.cache import cache
|
||||
from django.db.utils import DatabaseError
|
||||
|
||||
from .parameters import PARAMS
|
||||
|
||||
@ -73,7 +74,18 @@ class Config:
|
||||
def _populate_from_db(self):
|
||||
"""Cache data from latest ConfigRevision, then populate from cache"""
|
||||
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()
|
||||
logger.debug("Filled cache with data from latest ConfigRevision")
|
||||
self._populate_from_cache()
|
||||
|
Loading…
Reference in New Issue
Block a user