Less likely to trigger checking the JP param.
This commit is contained in:
@@ -1244,13 +1244,13 @@ def sql_delete(
|
||||
# If success then return the ID number
|
||||
# If not success and there is a table_name then check the database table passed
|
||||
# If found in database table then store in Redis and return the ID number
|
||||
# Updated 2023-11-15
|
||||
# Updated 2024-10-08
|
||||
@logger_reset
|
||||
def redis_lookup_id_random(
|
||||
record_id_random: int|str,
|
||||
table_name: str,
|
||||
check_int_id: bool = False,
|
||||
log_lvl: int = logging.WARNING, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
log_lvl: int = logging.INFO, # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
|
||||
minutes: int = 1,
|
||||
) -> str|int|bool|None:
|
||||
log.setLevel(log_lvl)
|
||||
@@ -1306,21 +1306,20 @@ def redis_lookup_id_random(
|
||||
key_name = f'{table_name}:{record_id_random}'
|
||||
|
||||
record_id = r.get(key_name)
|
||||
log.debug(f'Record ID found: {record_id}')
|
||||
# log.debug(f'Record ID found: {record_id}')
|
||||
|
||||
# WARNING WARNING WARNING
|
||||
# WARNING WARNING WARNING
|
||||
# WARNING WARNING WARNING
|
||||
log.info(f'Looking up ID in Redis is being partially bypassed. Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds')
|
||||
record_id = None # Uncomment this line to bypass the Redis lookup... trust?
|
||||
# log.info(f'Looking up ID in Redis is being partially bypassed. Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds')
|
||||
# record_id = None # Uncomment this line to bypass the Redis lookup... trust?
|
||||
# WARNING WARNING WARNING
|
||||
# WARNING WARNING WARNING
|
||||
# WARNING WARNING WARNING
|
||||
|
||||
if record_id:
|
||||
# log.info('The record ID was found using the record_id_random value.')
|
||||
r.setex(key_name, datetime.timedelta(minutes=1), value=record_id)
|
||||
log.info(f'Redis entry found. Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds')
|
||||
log.info(f'Redis: Entry found for: Key="{key_name}" value="{record_id}" TTL={r.ttl(key_name)} seconds')
|
||||
|
||||
return int(record_id)
|
||||
elif table_name:
|
||||
@@ -1332,10 +1331,10 @@ def redis_lookup_id_random(
|
||||
"""
|
||||
|
||||
if select_results := sql_select(sql=sql, data=data):
|
||||
log.debug(f'SQL SELECT result: {select_results}')
|
||||
log.debug(f'SQL: SELECT result: {select_results}')
|
||||
# log.debug(type(select_results))
|
||||
if isinstance(select_results, dict):
|
||||
log.info(f"""Record ID random found: {str(select_results.get('id'))}""")
|
||||
log.info(f"""SQL: Found ID Random for: {str(record_id_random)} = {str(select_results.get('id'))}""")
|
||||
if record_id := select_results.get('id'):
|
||||
r.setex(key_name, datetime.timedelta(minutes=minutes), value=record_id)
|
||||
|
||||
@@ -1344,11 +1343,11 @@ def redis_lookup_id_random(
|
||||
log.error('The SQL result was not what was expected. The ID field was not found.')
|
||||
return False
|
||||
else:
|
||||
log.error(f'More than one record may have been found in the table "{table_name}". There may be a duplicate id_random value in this table.')
|
||||
log.error(f'SQL: More than one record may have been found in the table "{table_name}". There may be a duplicate id_random value in this table.')
|
||||
log.error(select_results)
|
||||
return False
|
||||
else:
|
||||
log.info(f'Record ID random "{record_id_random}" was not found in table "{table_name}". Returning None.')
|
||||
log.warning(f'SQL: ID Random "{record_id_random}" was not found in table "{table_name}". Returning None.')
|
||||
return None
|
||||
|
||||
log.error('We should not be here. Something unexpected happened.')
|
||||
|
||||
Reference in New Issue
Block a user