Handle SQLAlchemy import errors

This commit is contained in:
Tulir Asokan 2018-03-02 20:40:03 +02:00
parent c1a8896faa
commit f805914c80

View File

@ -1,6 +1,10 @@
try:
from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, String, Integer, BLOB, orm from sqlalchemy import Column, String, Integer, BLOB, orm
import sqlalchemy as sql import sqlalchemy as sql
except ImportError:
sql = None
pass
from ..crypto import AuthKey from ..crypto import AuthKey
from ..tl.types import InputPhoto, InputDocument from ..tl.types import InputPhoto, InputDocument
@ -13,6 +17,8 @@ LATEST_VERSION = 1
class AlchemySessionContainer: class AlchemySessionContainer:
def __init__(self, engine=None, session=None, table_prefix="", def __init__(self, engine=None, session=None, table_prefix="",
table_base=None, manage_tables=True): table_base=None, manage_tables=True):
if not sql:
raise ImportError("SQLAlchemy not imported")
if isinstance(engine, str): if isinstance(engine, str):
engine = sql.create_engine(engine) engine = sql.create_engine(engine)