From 7c4cd02dfac58057ffd5c5f321e1af96afea3104 Mon Sep 17 00:00:00 2001 From: vabene1111 Date: Sun, 14 Nov 2021 10:33:33 +0100 Subject: [PATCH] fixed startup failing if fix tree fails --- cookbook/apps.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cookbook/apps.py b/cookbook/apps.py index 2b76c4573..2e31731df 100644 --- a/cookbook/apps.py +++ b/cookbook/apps.py @@ -1,15 +1,20 @@ +import traceback + from django.apps import AppConfig from django.conf import settings from django.db import OperationalError, ProgrammingError from django_scopes import scopes_disabled +from recipes.settings import DEBUG + class CookbookConfig(AppConfig): name = 'cookbook' def ready(self): # post_save signal is only necessary if using full-text search on postgres - if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2', 'django.db.backends.postgresql']: + if settings.DATABASES['default']['ENGINE'] in ['django.db.backends.postgresql_psycopg2', + 'django.db.backends.postgresql']: import cookbook.signals # noqa # when starting up run fix_tree to: @@ -21,6 +26,14 @@ class CookbookConfig(AppConfig): Keyword.fix_tree(fix_paths=True) Food.fix_tree(fix_paths=True) except OperationalError: + if DEBUG: + traceback.print_exc() pass # if model does not exist there is no need to fix it except ProgrammingError: + if DEBUG: + traceback.print_exc() pass # if migration has not been run database cannot be fixed yet + except Exception: + if DEBUG: + traceback.print_exc() + pass # dont break startup just because fix could not run, need to investigate cases when this happens