Skip to content

Commit f2ee3f3

Browse files
codewizdaveclaude
andcommitted
fix(data_import): use lazy imports to prevent excel-to-sql load errors
Replace module-level imports with lazy imports using __getattr__. This prevents excel-to-sql from being imported at application startup, which causes ImportError in the compiled Windows executable when the auto_pilot module is bundled but not properly initialized. The lazy import ensures excel-to-sql is only loaded when actually needed (e.g., during data import operations), not during module initialization or GUI startup. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent ffc833c commit f2ee3f3

1 file changed

Lines changed: 27 additions & 2 deletions

File tree

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,34 @@
11
"""Data import module for wareflow-analysis.
22
33
This module provides data import functionality using excel-to-sql Auto-Pilot Mode.
4+
5+
Note: Uses lazy imports to avoid triggering excel-to-sql imports at module load time.
6+
This prevents import errors when the module is imported but not actively used.
47
"""
58

6-
from wareflow_analysis.data_import.autopilot import generate_autopilot_config
7-
from wareflow_analysis.data_import.importer import run_import
9+
# Lazy imports - these are only imported when actually used
10+
# This prevents issues with excel-to-sql dependency loading
811

912
__all__ = ["generate_autopilot_config", "run_import"]
13+
14+
15+
def __getattr__(name: str):
16+
"""Lazy import attributes only when accessed.
17+
18+
Args:
19+
name: Attribute name being accessed
20+
21+
Returns:
22+
The requested attribute
23+
24+
Raises:
25+
AttributeError: If attribute doesn't exist
26+
"""
27+
if name == "generate_autopilot_config":
28+
from wareflow_analysis.data_import.autopilot import generate_autopilot_config
29+
return generate_autopilot_config
30+
elif name == "run_import":
31+
from wareflow_analysis.data_import.importer import run_import
32+
return run_import
33+
else:
34+
raise AttributeError(f"module '{__name__}' has no attribute '{name}'")

0 commit comments

Comments
 (0)