From f805914c80e034058789ec6d7fef43dd4762e051 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Fri, 2 Mar 2018 20:40:03 +0200 Subject: [PATCH] Handle SQLAlchemy import errors --- telethon/sessions/sqlalchemy.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/telethon/sessions/sqlalchemy.py b/telethon/sessions/sqlalchemy.py index aa618e4c..0b028c02 100644 --- a/telethon/sessions/sqlalchemy.py +++ b/telethon/sessions/sqlalchemy.py @@ -1,6 +1,10 @@ -from sqlalchemy.ext.declarative import declarative_base -from sqlalchemy import Column, String, Integer, BLOB, orm -import sqlalchemy as sql +try: + from sqlalchemy.ext.declarative import declarative_base + from sqlalchemy import Column, String, Integer, BLOB, orm + import sqlalchemy as sql +except ImportError: + sql = None + pass from ..crypto import AuthKey from ..tl.types import InputPhoto, InputDocument @@ -13,6 +17,8 @@ LATEST_VERSION = 1 class AlchemySessionContainer: def __init__(self, engine=None, session=None, table_prefix="", table_base=None, manage_tables=True): + if not sql: + raise ImportError("SQLAlchemy not imported") if isinstance(engine, str): engine = sql.create_engine(engine)