From 862fca1602bfbb3d0eaf1fb0fd133dd0a7eb0002 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 6 Mar 2022 13:38:10 +0100 Subject: [PATCH] conf: Use imports instead of sys.modules to detect module availability `conf.supybot.databases()` may be called without any plugin supporting sqlite3 being loaded yet, which causes `sqlite3` to be missing from `sys.modules`; so it wouldn't be used by plugins loaded afterward. --- src/conf.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/conf.py b/src/conf.py index fdd9800a3..b9314c2ff 100644 --- a/src/conf.py +++ b/src/conf.py @@ -1021,9 +1021,17 @@ class Databases(registry.SpaceSeparatedListOfStrings): v = super(Databases, self).__call__() if not v: v = ['anydbm', 'dbm', 'cdb', 'flat', 'pickle'] - if 'sqlalchemy' in sys.modules: + try: + import sqlalchemy + except ImportError: + pass + else: v.insert(0, 'sqlalchemy') - if 'sqlite3' in sys.modules: + try: + import sqlite3 + except ImportError: + pass + else: v.insert(0, 'sqlite3') return v