Less debug. Also why was this using the print() function? It should have been using the normal log.info() or whatever.
This commit is contained in:
@@ -135,7 +135,7 @@ def sql_search_qry_part(
|
||||
"""Recursively builds a SQL WHERE clause from a SearchQuery model."""
|
||||
from app import lib_sql_core
|
||||
data = {}
|
||||
param_counter = [0]
|
||||
param_counter = [0]
|
||||
|
||||
def get_param_name():
|
||||
param_counter[0] += 1
|
||||
@@ -157,11 +157,11 @@ def sql_search_qry_part(
|
||||
else:
|
||||
use_match = True
|
||||
if table_name:
|
||||
try:
|
||||
try:
|
||||
lib_sql_core.db.execute(text(f"SELECT default_qry_str FROM `{table_name}` LIMIT 0"))
|
||||
except:
|
||||
except:
|
||||
use_match = False
|
||||
else:
|
||||
else:
|
||||
use_match = False
|
||||
|
||||
if use_match:
|
||||
@@ -172,22 +172,22 @@ def sql_search_qry_part(
|
||||
like_clauses = []
|
||||
# Fields to exclude from a generic text 'q' search (numeric, technical, or date fields)
|
||||
exclude_patterns = [
|
||||
'enable', 'hide', 'priority', 'sort', 'group',
|
||||
'enable', 'hide', 'priority', 'sort', 'group',
|
||||
'created_on', 'updated_on'
|
||||
]
|
||||
for field in searchable_fields:
|
||||
# Exclude internal integer IDs specifically
|
||||
if field.endswith('_id') or field == 'id':
|
||||
continue
|
||||
|
||||
|
||||
# Exclude other technical/meta fields
|
||||
if any(x == field for x in exclude_patterns):
|
||||
continue
|
||||
|
||||
|
||||
f_p_name = get_param_name()
|
||||
like_clauses.append(f"`{field}` LIKE :{f_p_name}")
|
||||
data[f_p_name] = f"%{query_node.query_string}%"
|
||||
|
||||
|
||||
if like_clauses: clauses.append(f"({' OR '.join(like_clauses)})")
|
||||
for filter_attr in ['and_filters', 'or_filters']:
|
||||
if hasattr(query_node, filter_attr) and getattr(query_node, filter_attr):
|
||||
@@ -204,19 +204,19 @@ def sql_search_qry_part(
|
||||
|
||||
def process_filter(f) -> tuple[str, dict]:
|
||||
# --- ID VISION MAPPING ---
|
||||
# If the frontend uses clean names (id, account_id),
|
||||
# If the frontend uses clean names (id, account_id),
|
||||
# map them to the database columns (id_random, account_id_random)
|
||||
# ONLY if those columns actually exist in this table/view.
|
||||
target_field = f.field
|
||||
vision_fields = [
|
||||
'id', 'account_id', 'site_id', 'person_id', 'user_id',
|
||||
'journal_id', 'journal_entry_id', 'page_id', 'post_id',
|
||||
'id', 'account_id', 'site_id', 'person_id', 'user_id',
|
||||
'journal_id', 'journal_entry_id', 'page_id', 'post_id',
|
||||
'post_comment_id', 'organization_id', 'address_id', 'hosted_file_id'
|
||||
]
|
||||
|
||||
|
||||
if target_field in vision_fields:
|
||||
candidate_field = 'id_random' if target_field == 'id' else f"{target_field}_random"
|
||||
|
||||
|
||||
# Schema Check: Verify if the random version exists in the current table/view
|
||||
use_random = False
|
||||
if table_name:
|
||||
@@ -225,10 +225,10 @@ def sql_search_qry_part(
|
||||
use_random = True
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
if use_random:
|
||||
target_field = candidate_field
|
||||
print(f"Search Trace: Mapping filter field '{f.field}' -> '{target_field}'", flush=True)
|
||||
# print(f"Search Trace: Mapping filter field '{f.field}' -> '{target_field}'", flush=True)
|
||||
else:
|
||||
# If random doesn't exist, we must stick to the integer column
|
||||
# but we'll need to resolve the string value to an integer elsewhere
|
||||
@@ -239,7 +239,7 @@ def sql_search_qry_part(
|
||||
# Fallback check for original field just in case
|
||||
if f.field not in searchable_fields:
|
||||
raise HTTPException(status_code=400, detail=f"Unauthorized search field '{f.field}' (mapped to '{target_field}')")
|
||||
|
||||
|
||||
sql_op = operator_map.get(f.op.lower())
|
||||
if not sql_op: raise HTTPException(status_code=400, detail=f"Unsupported operator: {f.op}")
|
||||
filter_data = {}
|
||||
|
||||
Reference in New Issue
Block a user