mikeboone Claude Sonnet 4.6 commited on
Commit
579ca71
·
1 Parent(s): 2d76621

fix: retry population on failure, report all table counts, fail loudly if fact tables empty

Browse files

- After gen.generate(), check all tables for 0 rows
- If anything failed (exception or empty fact table), auto-retry once with truncate_first=True
- Log final row count for every table with pass/fail indicator
- Raise with combined error message if fact tables still empty after 2 attempts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. legitdata_bridge.py +34 -5
legitdata_bridge.py CHANGED
@@ -567,15 +567,44 @@ def populate_demo_data(
567
  log(f"Generating {size} dataset...")
568
  log(" This may take a few minutes...")
569
 
570
- results = gen.generate(size=size, truncate_first=truncate_first)
 
 
 
 
 
 
 
571
 
572
- # Verify fact tables have data empty fact table = unusable demo
573
  fact_table_names = {t.name for t in schema.fact_tables}
574
  empty_facts = [t for t in fact_table_names if results.get(t, 0) == 0]
575
- if empty_facts:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
576
  raise RuntimeError(
577
- f"Fact table(s) have 0 rows after population: {', '.join(empty_facts)}. "
578
- f"Check insert errors above."
579
  )
580
 
581
  # Format results
 
567
  log(f"Generating {size} dataset...")
568
  log(" This may take a few minutes...")
569
 
570
+ # Attempt 1
571
+ results = {}
572
+ first_attempt_error = None
573
+ try:
574
+ results = gen.generate(size=size, truncate_first=truncate_first)
575
+ except RuntimeError as e:
576
+ first_attempt_error = str(e)
577
+ log(f"⚠️ First population attempt failed: {first_attempt_error}")
578
 
579
+ # Check all tables for 0 rows even if no exception
580
  fact_table_names = {t.name for t in schema.fact_tables}
581
  empty_facts = [t for t in fact_table_names if results.get(t, 0) == 0]
582
+ if not first_attempt_error and empty_facts:
583
+ first_attempt_error = f"Fact table(s) empty after first attempt: {', '.join(empty_facts)}"
584
+ log(f"⚠️ {first_attempt_error}")
585
+
586
+ # Attempt 2 if anything failed
587
+ if first_attempt_error:
588
+ log("🔄 Retrying data population (attempt 2 of 2)...")
589
+ try:
590
+ results = gen.generate(size=size, truncate_first=True)
591
+ except RuntimeError as retry_e:
592
+ raise RuntimeError(
593
+ f"Population failed after 2 attempts. "
594
+ f"Attempt 1: {first_attempt_error} | Attempt 2: {retry_e}"
595
+ )
596
+
597
+ # Final check — report all table counts and fail if fact tables still empty
598
+ log("\nFinal table row counts:")
599
+ for table_name, count in sorted(results.items()):
600
+ status = "✅" if count > 0 else "❌"
601
+ log(f" {status} {table_name}: {count:,} rows")
602
+
603
+ empty_facts_final = [t for t in fact_table_names if results.get(t, 0) == 0]
604
+ if empty_facts_final:
605
  raise RuntimeError(
606
+ f"Fact table(s) still empty after 2 attempts: {', '.join(empty_facts_final)}. "
607
+ f"First attempt error: {first_attempt_error}"
608
  )
609
 
610
  # Format results