Skip to content

Commit 8ce1679

Browse files
committed
Fix NoneType error when connection is None
- Don't pass connection=None explicitly to SemanticLayer (use default parameter) - Fix workbench app.py to only pass connection if not None - Fix CLI commands (workbench, query, serve) to only pass connection if not None - Prevents 'NoneType' object has no attribute 'startswith' error
1 parent 56995cf commit 8ce1679

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

sidemantic/cli.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,11 @@ def workbench(
112112
# Use connection from config
113113
connection_str = build_connection_string(_loaded_config)
114114

115-
run_workbench(directory, connection=connection_str)
115+
# Only pass connection if it's not None
116+
if connection_str:
117+
run_workbench(directory, connection=connection_str)
118+
else:
119+
run_workbench(directory)
116120

117121

118122
@app.command()
@@ -193,8 +197,11 @@ def query(
193197
if db_files:
194198
connection_str = f"duckdb:///{db_files[0].absolute()}"
195199

196-
# Load semantic layer
197-
layer = SemanticLayer(connection=connection_str)
200+
# Load semantic layer (only pass connection if not None)
201+
if connection_str:
202+
layer = SemanticLayer(connection=connection_str)
203+
else:
204+
layer = SemanticLayer()
198205
load_from_directory(layer, str(directory))
199206

200207
if not layer.graph.models:
@@ -439,17 +446,17 @@ def serve(
439446
elif _loaded_config and _loaded_config.connection:
440447
# Use connection from config
441448
connection_str = build_connection_string(_loaded_config)
442-
else:
443-
# Default to in-memory DuckDB
444-
connection_str = "duckdb:///:memory:"
445449

446450
# Resolve port, username, password from args or config
447451
port_resolved = port if port is not None else (_loaded_config.pg_server.port if _loaded_config else 5433)
448452
username_resolved = username or (_loaded_config.pg_server.username if _loaded_config else None)
449453
password_resolved = password or (_loaded_config.pg_server.password if _loaded_config else None)
450454

451-
# Create semantic layer with connection string
452-
layer = SemanticLayer(connection=connection_str)
455+
# Create semantic layer (only pass connection if not None, otherwise use default)
456+
if connection_str:
457+
layer = SemanticLayer(connection=connection_str)
458+
else:
459+
layer = SemanticLayer()
453460

454461
# Load models
455462
load_from_directory(layer, str(directory))

sidemantic/workbench/app.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,12 @@ def on_mount(self) -> None:
326326
db_files = list(data_dir.glob("*.db"))
327327
if db_files:
328328
connection = f"duckdb:///{db_files[0].absolute()}"
329-
self.layer = SemanticLayer(connection=connection)
329+
330+
# Only pass connection if it's not None (to use default parameter)
331+
if connection:
332+
self.layer = SemanticLayer(connection=connection)
333+
else:
334+
self.layer = SemanticLayer()
330335

331336
# Load semantic layer models
332337
load_from_directory(self.layer, str(self.directory))

0 commit comments

Comments
 (0)