From 87d25bc920a20683cfcbe8ce3ff77cf1239d658d Mon Sep 17 00:00:00 2001 From: jsjiang Date: Tue, 26 Sep 2023 17:15:30 -0700 Subject: [PATCH] add error control to handle select_for_update on non existing row --- impl/nog_sql/ezid_minter.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/impl/nog_sql/ezid_minter.py b/impl/nog_sql/ezid_minter.py index 5d301c23..5767e7f8 100755 --- a/impl/nog_sql/ezid_minter.py +++ b/impl/nog_sql/ezid_minter.py @@ -570,16 +570,19 @@ def get_list(self, key_str): return self.get(key_str).split() def get_minter_from_db(self): - minter = ezidapp.models.minter.Minter.objects.select_for_update().filter(prefix=self._prefix) - if minter.exists(): - if self._is_new: - raise Exception(f"Minter with this prefix already exists. Prefix: {self._prefix}") + try: + minter = ezidapp.models.minter.Minter.objects.select_for_update().filter(prefix=self._prefix) + if minter.exists(): + if self._is_new: + raise Exception(f"Minter with this prefix already exists. Prefix: {self._prefix}") + else: + self._minter = minter.first() + self._minterState = minter.first().minterState else: - self._minter = minter.first() - self._minterState = minter.first().minterState - else: - if self._is_new == False: - raise Exception(f"Minter with this prefix does not exist. Prefix: {self._prefix}") + if self._is_new == False: + raise Exception(f"Minter with this prefix does not exist. Prefix: {self._prefix}") + except Exception as ex: + log.info(f'Minter table select_for_update error: {ex}') class _Drand48: