From 8e59170b769e3adee80490636c71427f60f2b92d Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Thu, 15 Nov 2018 15:15:07 +0100 Subject: [PATCH] Do not try to access the database during migrations --- openslides/core/apps.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/openslides/core/apps.py b/openslides/core/apps.py index 0ca5ba32a..a4cf3c05e 100644 --- a/openslides/core/apps.py +++ b/openslides/core/apps.py @@ -1,12 +1,11 @@ +import sys from collections import OrderedDict from operator import attrgetter from typing import Any, Dict, List, Set from django.apps import AppConfig from django.conf import settings -from django.core.exceptions import ImproperlyConfigured from django.db.models.signals import post_migrate -from django.db.utils import OperationalError, ProgrammingError from ..utils.projector import register_projector_elements @@ -50,12 +49,17 @@ class CoreAppConfig(AppConfig): # Collect all config variables before getting the constants. 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 - try: + if is_normal_server_start: set_constants(get_constants_from_apps()) - except (ImproperlyConfigured, OperationalError, ProgrammingError): - # Database is not loaded. This happens in tests and migrations. - pass # Define 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) # Sets the cache - try: + if is_normal_server_start: element_cache.ensure_cache() - except (ImproperlyConfigured, OperationalError, ProgrammingError): - # This happens in the tests or in migrations. Do nothing - pass # Register client messages register_client_message(NotifyWebsocketClientMessage())