Skip to content

Commit

Permalink
add error control to handle select_for_update on non existing row
Browse files Browse the repository at this point in the history
  • Loading branch information
jsjiang committed Sep 27, 2023
1 parent 7af59ec commit 87d25bc
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions impl/nog_sql/ezid_minter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 87d25bc

Please sign in to comment.