From 5fac520b2a1d168387319548c6674d89928f0067 Mon Sep 17 00:00:00 2001 From: robin Date: Sat, 27 Jan 2018 13:02:30 -0500 Subject: [PATCH] Raise the sqlite3 import error, not the pysqlite2 one Fixed the import error raised when a platform has neither pysqlite2 nor sqlite3 installed, such that the sqlite3-related import error is raised, not the pysqlite2 one which is not the actual failure mode. Pull request courtesy Robin. Origin version only print `No module named pysqlite2` even it's actually the import error of line 337: `from sqlite3 import dbapi2 as sqlite` which point user to the wrong debug direction. It should raise `e.message` as `No module named _sqlite3`. Change-Id: Idc39cd0d226957fd670859df23a2386dea6eb3cc Pull-request: https://github.com/zzzeek/sqlalchemy/pull/417 --- doc/build/changelog/unreleased_12/sqlite_import.rst | 8 ++++++++ lib/sqlalchemy/dialects/sqlite/pysqlite.py | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 doc/build/changelog/unreleased_12/sqlite_import.rst diff --git a/doc/build/changelog/unreleased_12/sqlite_import.rst b/doc/build/changelog/unreleased_12/sqlite_import.rst new file mode 100644 index 0000000000..55f3eb5117 --- /dev/null +++ b/doc/build/changelog/unreleased_12/sqlite_import.rst @@ -0,0 +1,8 @@ +.. change:: + :tags: bug, sqlite + + Fixed the import error raised when a platform + has neither pysqlite2 nor sqlite3 installed, such + that the sqlite3-related import error is raised, + not the pysqlite2 one which is not the actual + failure mode. Pull request courtesy Robin. diff --git a/lib/sqlalchemy/dialects/sqlite/pysqlite.py b/lib/sqlalchemy/dialects/sqlite/pysqlite.py index a5e84f7bcd..8809962df2 100644 --- a/lib/sqlalchemy/dialects/sqlite/pysqlite.py +++ b/lib/sqlalchemy/dialects/sqlite/pysqlite.py @@ -332,10 +332,10 @@ class SQLiteDialect_pysqlite(SQLiteDialect): def dbapi(cls): try: from pysqlite2 import dbapi2 as sqlite - except ImportError as e: + except ImportError: try: from sqlite3 import dbapi2 as sqlite # try 2.5+ stdlib name. - except ImportError: + except ImportError as e: raise e return sqlite -- 2.47.3