Compare commits

...

7 Commits

Author SHA1 Message Date
Andrew Morgan
3dace4b1aa uh 2020-03-25 15:50:40 +00:00
Andrew Morgan
4ac60a17a5 Possibly appease mypy 2020-03-25 15:46:28 +00:00
Andrew Morgan
f5fd9b98c7 Don't import Sqlite3Engine unless running synapse with sqlite3 2020-03-25 15:42:25 +00:00
Andrew Morgan
8895c38202 Use MYPY variable instead 2020-03-25 15:31:44 +00:00
Andrew Morgan
e0ee1b2224 __future__ import 2020-03-25 15:29:48 +00:00
Andrew Morgan
14c4f08f5c Add changelog 2020-03-25 15:24:58 +00:00
Andrew Morgan
cb76e53b7f Only import sqlite3 by default if running mypy checks 2020-03-25 15:23:46 +00:00
3 changed files with 12 additions and 5 deletions

1
changelog.d/7143.bugfix Normal file
View File

@@ -0,0 +1 @@
Prevent `sqlite3` module from being imported even when using the postgres backend.

View File

@@ -15,25 +15,28 @@
import platform import platform
from ._base import BaseDatabaseEngine, IncorrectDatabaseSetup from ._base import BaseDatabaseEngine, IncorrectDatabaseSetup
from .postgres import PostgresEngine
from .sqlite import Sqlite3Engine MYPY = False
def create_engine(database_config) -> BaseDatabaseEngine: def create_engine(database_config) -> BaseDatabaseEngine:
name = database_config["name"] name = database_config["name"]
if name == "sqlite3": if name == "sqlite3" or MYPY:
import sqlite3 import sqlite3
from .sqlite import Sqlite3Engine
return Sqlite3Engine(sqlite3, database_config) return Sqlite3Engine(sqlite3, database_config)
if name == "psycopg2": if name == "psycopg2" or MYPY:
# pypy requires psycopg2cffi rather than psycopg2 # pypy requires psycopg2cffi rather than psycopg2
if platform.python_implementation() == "PyPy": if platform.python_implementation() == "PyPy":
import psycopg2cffi as psycopg2 # type: ignore import psycopg2cffi as psycopg2 # type: ignore
else: else:
import psycopg2 # type: ignore import psycopg2 # type: ignore
from .postgres import PostgresEngine
return PostgresEngine(psycopg2, database_config) return PostgresEngine(psycopg2, database_config)
raise RuntimeError("Unsupported database engine '%s'" % (name,)) raise RuntimeError("Unsupported database engine '%s'" % (name,))

View File

@@ -12,12 +12,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import sqlite3
import struct import struct
import threading import threading
from synapse.storage.engines import BaseDatabaseEngine from synapse.storage.engines import BaseDatabaseEngine
MYPY = False
if MYPY:
import sqlite3
class Sqlite3Engine(BaseDatabaseEngine[sqlite3.Connection]): class Sqlite3Engine(BaseDatabaseEngine[sqlite3.Connection]):
def __init__(self, database_module, database_config): def __init__(self, database_module, database_config):