Skip to content

Commit 29842be

Browse files
simonwclaude
andcommitted
Fix type errors in cli.py and db.py
- Add type annotation for Database.conn to fix context manager errors - Convert exception objects to str() when raising ClickException - Handle None return from find_spatialite() with proper error message 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent 116cc99 commit 29842be

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

sqlite_utils/cli.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def analyze(path, names):
393393
else:
394394
db.analyze()
395395
except OperationalError as e:
396-
raise click.ClickException(e)
396+
raise click.ClickException(str(e))
397397

398398

399399
@cli.command()
@@ -536,7 +536,7 @@ def add_foreign_key(
536536
try:
537537
db[table].add_foreign_key(column, other_table, other_column, ignore=ignore)
538538
except AlterError as e:
539-
raise click.ClickException(e)
539+
raise click.ClickException(str(e))
540540

541541

542542
@cli.command(name="add-foreign-keys")
@@ -571,7 +571,7 @@ def add_foreign_keys(path, foreign_key, load_extension):
571571
try:
572572
db.add_foreign_keys(tuples)
573573
except AlterError as e:
574-
raise click.ClickException(e)
574+
raise click.ClickException(str(e))
575575

576576

577577
@cli.command(name="index-foreign-keys")
@@ -3361,7 +3361,10 @@ def _load_extensions(db, load_extension):
33613361
db.conn.enable_load_extension(True)
33623362
for ext in load_extension:
33633363
if ext == "spatialite" and not os.path.exists(ext):
3364-
ext = find_spatialite()
3364+
found = find_spatialite()
3365+
if found is None:
3366+
raise click.ClickException("Could not find SpatiaLite extension")
3367+
ext = found
33653368
if ":" in ext:
33663369
path, _, entrypoint = ext.partition(":")
33673370
db.conn.execute("SELECT load_extension(?, ?)", [path, entrypoint])

sqlite_utils/db.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class Database:
328328

329329
_counts_table_name = "_counts"
330330
use_counts_table = False
331+
conn: sqlite3.Connection
331332

332333
def __init__(
333334
self,

0 commit comments

Comments
 (0)