mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-11-03 22:55:43 +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.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)})")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -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)})")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user