Less likely to trigger checking the JP param.

This commit is contained in:
Scott Idem
2024-10-08 13:29:27 -04:00
parent cd0d3fe9d5
commit 39a1c05df1
2 changed files with 18 additions and 16 deletions

View File

@@ -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.')

View File

@@ -367,7 +367,7 @@ def handle_get_obj_li(
commons: Common_Route_Params = None,
):
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(locals())
import urllib
@@ -388,8 +388,9 @@ def handle_get_obj_li(
or_like_dict_obj = None
jp_obj = None
if jp:
log.setLevel(logging.DEBUG) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug(jp)
if jp and jp != '%7B%7D': # NOTE: This is the URL encoded version of '{}'. -2024-10-08
# log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.debug( urllib.parse.unquote(jp) )
try:
jp_obj = json.loads(urllib.parse.unquote(jp))
@@ -414,8 +415,10 @@ def handle_get_obj_li(
if jp_obj.get('and_in_li'): # NOTE: This is for the additional AND IN clauses in the WHERE statement
and_in_dict_li_obj = jp_obj['and_in_li']
log.setLevel(logging.WARNING) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
log.setLevel(logging.INFO) # DEBUG, INFO, WARNING, ERROR, EXCEPTION, CRITICAL
else:
log.debug('No jp_obj')
pass
if order_by_li:
order_by_li = json.loads(order_by_li)