Merge pull request #4016 from FinnStutzenstein/postgres_no_error
Do not try to access the database during migrations
This commit is contained in:
commit
14b2d33d00
@ -1,12 +1,11 @@
|
|||||||
|
import sys
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from typing import Any, Dict, List, Set
|
from typing import Any, Dict, List, Set
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
|
||||||
from django.db.models.signals import post_migrate
|
from django.db.models.signals import post_migrate
|
||||||
from django.db.utils import OperationalError, ProgrammingError
|
|
||||||
|
|
||||||
from ..utils.projector import register_projector_elements
|
from ..utils.projector import register_projector_elements
|
||||||
|
|
||||||
@ -50,12 +49,17 @@ class CoreAppConfig(AppConfig):
|
|||||||
# Collect all config variables before getting the constants.
|
# Collect all config variables before getting the constants.
|
||||||
config.collect_config_variables_from_apps()
|
config.collect_config_variables_from_apps()
|
||||||
|
|
||||||
|
# Skip all database related accesses during migrations.
|
||||||
|
is_normal_server_start = False
|
||||||
|
for sys_part in sys.argv:
|
||||||
|
for entry in ('runserver', 'gunicorn', 'daphne'):
|
||||||
|
if sys_part.endswith(entry):
|
||||||
|
is_normal_server_start = True
|
||||||
|
break
|
||||||
|
|
||||||
# Set constants
|
# Set constants
|
||||||
try:
|
if is_normal_server_start:
|
||||||
set_constants(get_constants_from_apps())
|
set_constants(get_constants_from_apps())
|
||||||
except (ImproperlyConfigured, OperationalError, ProgrammingError):
|
|
||||||
# Database is not loaded. This happens in tests and migrations.
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Define projector elements.
|
# Define projector elements.
|
||||||
register_projector_elements(get_projector_elements())
|
register_projector_elements(get_projector_elements())
|
||||||
@ -79,11 +83,8 @@ class CoreAppConfig(AppConfig):
|
|||||||
router.register(self.get_model('Countdown').get_collection_string(), CountdownViewSet)
|
router.register(self.get_model('Countdown').get_collection_string(), CountdownViewSet)
|
||||||
|
|
||||||
# Sets the cache
|
# Sets the cache
|
||||||
try:
|
if is_normal_server_start:
|
||||||
element_cache.ensure_cache()
|
element_cache.ensure_cache()
|
||||||
except (ImproperlyConfigured, OperationalError, ProgrammingError):
|
|
||||||
# This happens in the tests or in migrations. Do nothing
|
|
||||||
pass
|
|
||||||
|
|
||||||
# Register client messages
|
# Register client messages
|
||||||
register_client_message(NotifyWebsocketClientMessage())
|
register_client_message(NotifyWebsocketClientMessage())
|
||||||
|
Loading…
Reference in New Issue
Block a user