mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-04 15:15:42 +00:00 
			
		
		
		
	Catch OperationalError when updating exchange rates (#5438)
- Can occur if the database is not yet ready
This commit is contained in:
		@@ -9,7 +9,7 @@ from django.conf import settings
 | 
			
		||||
from django.contrib.auth import get_user_model
 | 
			
		||||
from django.core.exceptions import AppRegistryNotReady
 | 
			
		||||
from django.db import transaction
 | 
			
		||||
from django.db.utils import IntegrityError
 | 
			
		||||
from django.db.utils import IntegrityError, OperationalError
 | 
			
		||||
 | 
			
		||||
import InvenTree.conversion
 | 
			
		||||
import InvenTree.tasks
 | 
			
		||||
@@ -159,6 +159,8 @@ class InvenTreeConfig(AppConfig):
 | 
			
		||||
        if update:
 | 
			
		||||
            try:
 | 
			
		||||
                update_exchange_rates()
 | 
			
		||||
            except OperationalError:
 | 
			
		||||
                logger.warning("Could not update exchange rates - database not ready")
 | 
			
		||||
            except Exception as e:
 | 
			
		||||
                logger.error(f"Error updating exchange rates: {e} ({type(e)})")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -520,6 +520,8 @@ def update_exchange_rates():
 | 
			
		||||
 | 
			
		||||
        # Remove any exchange rates which are not in the provided currencies
 | 
			
		||||
        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
 | 
			
		||||
        logger.error(f"Error updating exchange rates: {e} ({type(e)})")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user