Peter Mutwiri commited on
Commit
aa9f7a3
·
1 Parent(s): dabb284

fixed Bind the Parameter Outside the String

Browse files
Files changed (1) hide show
  1. app/mapper.py +7 -2
app/mapper.py CHANGED
@@ -206,17 +206,22 @@ def canonify_df(org_id: str, source_id: str, hours_window: int = 24) -> tuple[pd
206
  # Load dynamic aliases before mapping
207
  load_dynamic_aliases()
208
 
 
209
  # 1️⃣ FETCH RAW AUDIT DATA
210
  with get_conn(org_id) as conn:
211
  ensure_raw_table(conn)
 
 
 
 
212
  try:
213
  rows = conn.execute("""
214
  SELECT row_data FROM main.raw_rows
215
  WHERE row_data IS NOT NULL
216
  AND LENGTH(CAST(row_data AS TEXT)) > 0
217
- AND ingested_at >= CURRENT_TIMESTAMP - INTERVAL '? hours'
218
  ORDER BY ingested_at DESC
219
- """, (hours_window,)).fetchall()
220
  except Exception as e:
221
  print(f"[canonify] ❌ SQL read error: {e}")
222
  return pd.DataFrame(), "unknown", 0.0
 
206
  # Load dynamic aliases before mapping
207
  load_dynamic_aliases()
208
 
209
+ # 1️⃣ FETCH RAW AUDIT DATA
210
  # 1️⃣ FETCH RAW AUDIT DATA
211
  with get_conn(org_id) as conn:
212
  ensure_raw_table(conn)
213
+
214
+ # ✅ FIXED: Calculate cutoff in Python, bind properly
215
+ cutoff_time = datetime.now() - timedelta(hours=hours_window)
216
+
217
  try:
218
  rows = conn.execute("""
219
  SELECT row_data FROM main.raw_rows
220
  WHERE row_data IS NOT NULL
221
  AND LENGTH(CAST(row_data AS TEXT)) > 0
222
+ AND ingested_at >= ?
223
  ORDER BY ingested_at DESC
224
+ """, (cutoff_time,)).fetchall()
225
  except Exception as e:
226
  print(f"[canonify] ❌ SQL read error: {e}")
227
  return pd.DataFrame(), "unknown", 0.0