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.
This commit is contained in:
Valentin Lorentz 2022-03-06 13:38:10 +01:00
parent d58d8d4a71
commit 862fca1602

View File

@ -1021,9 +1021,17 @@ class Databases(registry.SpaceSeparatedListOfStrings):
v = super(Databases, self).__call__() v = super(Databases, self).__call__()
if not v: if not v:
v = ['anydbm', 'dbm', 'cdb', 'flat', 'pickle'] v = ['anydbm', 'dbm', 'cdb', 'flat', 'pickle']
if 'sqlalchemy' in sys.modules: try:
import sqlalchemy
except ImportError:
pass
else:
v.insert(0, 'sqlalchemy') v.insert(0, 'sqlalchemy')
if 'sqlite3' in sys.modules: try:
import sqlite3
except ImportError:
pass
else:
v.insert(0, 'sqlite3') v.insert(0, 'sqlite3')
return v return v