]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Raise the sqlite3 import error, not the pysqlite2 one
authorrobin <y8765gd@gmail.com>
Sat, 27 Jan 2018 18:02:30 +0000 (13:02 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 27 Jan 2018 18:06:15 +0000 (13:06 -0500)
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 [new file with mode: 0644]
lib/sqlalchemy/dialects/sqlite/pysqlite.py

diff --git a/doc/build/changelog/unreleased_12/sqlite_import.rst b/doc/build/changelog/unreleased_12/sqlite_import.rst
new file mode 100644 (file)
index 0000000..55f3eb5
--- /dev/null
@@ -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.
index a5e84f7bcd51e16746e86de4832d570c54c1be9b..8809962df2056f9c3029f38b0c4e152b877f0d76 100644 (file)
@@ -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