Catch OperationalError when updating exchange rates (#5438)

- Can occur if the database is not yet ready
This commit is contained in:
Oliver 2023-08-14 14:16:11 +10:00 committed by GitHub
parent 6707f18f73
commit 9a8c8961e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View File

@ -9,7 +9,7 @@ from django.conf import settings
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.core.exceptions import AppRegistryNotReady from django.core.exceptions import AppRegistryNotReady
from django.db import transaction from django.db import transaction
from django.db.utils import IntegrityError from django.db.utils import IntegrityError, OperationalError
import InvenTree.conversion import InvenTree.conversion
import InvenTree.tasks import InvenTree.tasks
@ -159,6 +159,8 @@ class InvenTreeConfig(AppConfig):
if update: if update:
try: try:
update_exchange_rates() update_exchange_rates()
except OperationalError:
logger.warning("Could not update exchange rates - database not ready")
except Exception as e: except Exception as e:
logger.error(f"Error updating exchange rates: {e} ({type(e)})") logger.error(f"Error updating exchange rates: {e} ({type(e)})")

View File

@ -520,6 +520,8 @@ def update_exchange_rates():
# Remove any exchange rates which are not in the provided currencies # Remove any exchange rates which are not in the provided currencies
Rate.objects.filter(backend="InvenTreeExchange").exclude(currency__in=currency_codes()).delete() Rate.objects.filter(backend="InvenTreeExchange").exclude(currency__in=currency_codes()).delete()
except OperationalError:
logger.warning("Could not update exchange rates - database not ready")
except Exception as e: # pragma: no cover except Exception as e: # pragma: no cover
logger.error(f"Error updating exchange rates: {e} ({type(e)})") logger.error(f"Error updating exchange rates: {e} ({type(e)})")