Spaces:
Sleeping
Sleeping
File size: 1,858 Bytes
f4648a3 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | import os
import uuid
import sys
import logging
from dotenv import load_dotenv
from supabase import create_client, Client
# Add ml-api to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from utils.audit import AuditLogger
# Configure logging to see AuditLogger internal errors
logging.basicConfig(level=logging.INFO)
# Load credentials
load_dotenv('ml-api/.env')
url = os.environ.get("SUPABASE_URL")
key = os.environ.get("SUPABASE_SERVICE_ROLE_KEY")
if not url or not key:
print("ERROR: SUPABASE_URL or SUPABASE_SERVICE_ROLE_KEY missing from ml-api/.env")
exit(1)
print(f"Connecting to: {url}")
try:
supabase: Client = create_client(url, key)
logger = AuditLogger(supabase)
tx_id = str(uuid.uuid4())
print(f"Attempting to log test prediction for ID: {tx_id}...")
# This calls the log_activity RPC
# We'll use a direct try-except here to see the EXACT error if it fails
try:
res = supabase.rpc("log_activity", {
"p_action_type": "ML_PREDICTION",
"p_message": f"CONNECTION VERIFY: 0.99",
"p_resource_type": "transaction",
"p_resource_id": str(tx_id),
"p_metadata": {"test": "connection_verify"}
}).execute()
print("RPC call executed successfully.")
except Exception as rpc_err:
print(f"RPC ERROR: {str(rpc_err)}")
raise rpc_err
print("Checking if it exists in DB...")
# Verification query
res = supabase.table("audit_logs").select("*").eq("resource_id", tx_id).execute()
if len(res.data) > 0:
print(f"SUCCESS! Found log in Supabase: {res.data[0]['human_readable_message']}")
else:
print("FAIL: Call finished but no record found in audit_logs table.")
except Exception as e:
print(f"CRITICAL ERROR during verification: {str(e)}") |