""" check_ammar_csv_callbacks.py -- read-only: CSV-imported leads added by Ammar Ali that have a callback scheduled, and whether each one would actually show on Pipeline right now. User request, 2026-09-23: "csv import sy Ammar Ali ny jo lead add ki hain or us me action perform kye callbacks waly, woh lead humny pipeline me add krna hai" -- Pipeline's own inScope filter (components/pipeline/pipeline-view.tsx) already shows ANY lead with callback_at set, regardless of source/who added it, automatically -- so this checks whether that's actually true for these leads, or whether something is stopping them from showing up (hidden, no callback_at despite the disposition, etc). uv run python scripts/check_ammar_csv_callbacks.py Read-only -- prints what it finds, changes nothing. """ from __future__ import annotations import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from sqlalchemy import select # noqa: E402 from app.database import SessionLocal # noqa: E402 from app.models import Lead, User # noqa: E402 def main() -> int: db = SessionLocal() try: ammar = db.scalar(select(User).where(User.name.ilike("%ammar%"))) if not ammar: print("No user matching 'ammar' found.") return 1 print(f"Matched user: #{ammar.id} {ammar.name} <{ammar.email}>\n") leads = list( db.scalars( select(Lead) .where(Lead.source_prompt == "CSV Batch Import", Lead.created_by_user_id == ammar.id) .order_by(Lead.created_at) ).all() ) print(f"{len(leads)} CSV-imported lead(s) added by {ammar.name} total.\n") with_callback = [l for l in leads if l.callback_at is not None] print(f"{len(with_callback)} of those have callback_at set:\n") if not with_callback: print("(none -- if a callback disposition was applied, it should have set this; check the") print(" call_events / trace_csv_actions.py output for what outcome was actually recorded.)") return 0 for lead in with_callback: would_show = lead.hidden_at is None print(f"#{lead.id:<6} {lead.company_name}") print(f" stage={lead.pipeline_stage} callback_at={lead.callback_at} hidden_at={lead.hidden_at}") print(f" would show on Pipeline right now: {'YES' if would_show else 'NO -- hidden_at is set'}") print() return 0 finally: db.close() if __name__ == "__main__": sys.exit(main())