Q:

AttributeError: __enter__ using with statement SqlAlchemy session

im getting this AttributeError: __enter__ when i try to use sqlalchemy session like in this guide.
my code:
Session = scoped_session(sessionmaker(autoflush=True, autocommit=False, bind=engine))

@contextmanager
def session_scope():
    session = Session()
    try:
        yield session
        session.commit()
    except:
        session.rollback()
        raise
    finally:
        session.close()

class SomeClass:

    def __init__(self):
        self.session_scope = session_scope

    def something_with_session(self):

        with self.session_scope as session: <-- error

What am I doing wrong? I'm using python 3.6

A:

You have to call the function to get the context
with self.session_scope() as session:
    ...

