Update app/mapper.py
Browse files- app/mapper.py +2 -2
app/mapper.py
CHANGED
|
@@ -45,7 +45,7 @@ def ensure_canonical_table(duck: duckdb.DuckDBPyConnection, df: pd.DataFrame) ->
|
|
| 45 |
""")
|
| 46 |
|
| 47 |
# Get existing columns (lowercase for comparison)
|
| 48 |
-
|
| 49 |
|
| 50 |
# ✅ BULLETPROOF: Add missing columns with safe name handling
|
| 51 |
for col in df.columns:
|
|
@@ -210,7 +210,7 @@ def canonify_df(org_id: str, hours_window: int = 24) -> tuple[pd.DataFrame, str,
|
|
| 210 |
if not df.empty:
|
| 211 |
# Get current table columns
|
| 212 |
table_info = duck.execute(f"PRAGMA table_info('{table_name}')").fetchall()
|
| 213 |
-
table_cols = [r[0] for r in table_info]
|
| 214 |
|
| 215 |
# Only insert columns that exist in table
|
| 216 |
df_to_insert = df[[col for col in df.columns if col in table_cols]]
|
|
|
|
| 45 |
""")
|
| 46 |
|
| 47 |
# Get existing columns (lowercase for comparison)
|
| 48 |
+
existing_cols_raw = duck.execute(f"PRAGMA table_info('{table_name}')").fetchall()existing_cols = {str(r[0]).lower() for r in existing_cols_raw} # ✅ FORCE STRING
|
| 49 |
|
| 50 |
# ✅ BULLETPROOF: Add missing columns with safe name handling
|
| 51 |
for col in df.columns:
|
|
|
|
| 210 |
if not df.empty:
|
| 211 |
# Get current table columns
|
| 212 |
table_info = duck.execute(f"PRAGMA table_info('{table_name}')").fetchall()
|
| 213 |
+
table_cols = [str(r[0]) for r in table_info] # ✅ FORCE STRING
|
| 214 |
|
| 215 |
# Only insert columns that exist in table
|
| 216 |
df_to_insert = df[[col for col in df.columns if col in table_cols]]
|