From ce67fd1c6171633aa1cf74f00fc3fb1da86178a7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 25 Jun 2022 15:30:54 +1000 Subject: [PATCH] Exchange backend fix (#3253) * Prevent creation of duplicate backend objects * Ignore exchange errors, rather than returning None * Revert "Prevent creation of duplicate backend objects" This reverts commit 0b6d1ce86ff2d8471897f454720f5a7fbb62e10d. --- InvenTree/InvenTree/exchange.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/exchange.py b/InvenTree/InvenTree/exchange.py index 684802c52e..0225270f27 100644 --- a/InvenTree/InvenTree/exchange.py +++ b/InvenTree/InvenTree/exchange.py @@ -44,8 +44,9 @@ class InvenTreeExchange(SimpleExchangeBackend): response = urlopen(url, timeout=5, context=context) return response.read() except Exception: - # Returning None here will raise an error upstream - return None + # Something has gone wrong, but we can just try again next time + # Raise a TypeError so the outer function can handle this + raise TypeError def update_rates(self, base_currency=None): """Set the requested currency codes and get rates.""" @@ -60,6 +61,8 @@ class InvenTreeExchange(SimpleExchangeBackend): # catch connection errors except URLError: print('Encountered connection error while updating') + except TypeError: + print('Exchange returned invalid response') except OperationalError as e: if 'SerializationFailure' in e.__cause__.__class__.__name__: print('Serialization Failure while updating exchange rates')