Add exceptions.GenerateIDFailed.
This commit is contained in:
parent
d1b0fb6aec
commit
b99c594931
2 changed files with 5 additions and 1 deletions
|
@ -187,6 +187,9 @@ class FeatureDisabled(EtiquetteException):
|
||||||
'''
|
'''
|
||||||
error_message = 'This feature has been disabled. Requires {requires}.'
|
error_message = 'This feature has been disabled. Requires {requires}.'
|
||||||
|
|
||||||
|
class GenerateIDFailed(EtiquetteException):
|
||||||
|
error_message = 'Could not generate unique ID on {table}. You should increase ID bits.'
|
||||||
|
|
||||||
class MinMaxInvalid(EtiquetteException):
|
class MinMaxInvalid(EtiquetteException):
|
||||||
'''
|
'''
|
||||||
For when the user searches for e.g. width=a-b but the a-b can't be parsed.
|
For when the user searches for e.g. width=a-b but the a-b can't be parsed.
|
||||||
|
|
|
@ -1236,10 +1236,11 @@ class PhotoDB(
|
||||||
table = thing_class.table
|
table = thing_class.table
|
||||||
|
|
||||||
length = self.config['id_bits']
|
length = self.config['id_bits']
|
||||||
while True:
|
for retry in range(10):
|
||||||
id = RNG.getrandbits(length)
|
id = RNG.getrandbits(length)
|
||||||
if not self.exists(f'SELECT 1 FROM {table} WHERE id == ?', [id]):
|
if not self.exists(f'SELECT 1 FROM {table} WHERE id == ?', [id]):
|
||||||
return id
|
return id
|
||||||
|
raise exceptions.GenerateIDFailed(table=table)
|
||||||
|
|
||||||
def load_config(self) -> None:
|
def load_config(self) -> None:
|
||||||
log.debug('Loading config file.')
|
log.debug('Loading config file.')
|
||||||
|
|
Loading…
Reference in a new issue