def get_session(db_engine: Engine) -> ContextManager[Session]:
    """Get session from database engine.

    Example:
        with get_session(db_engine) as session:
            # write your query, do not need to handle database connection
            session.query(MODEL).filter_by(field=value).first()
    """
    try:
        session: Session = sessionmaker(bind=db_engine, **SESSION_OPTIONS)()
    except Exception:
        raise Exception('unknown db engine')

    try:
        yield session
    except Exception:
        session.rollback()
        raise
    finally:
        session.close()
Get session from database engine.

    Example:
        with get_session(db_engine) as session:
            # write your query, do not need to handle database connection
            session.query(MODEL).filter_by(field=value).first()
    
web_console_v2/api/fedlearner_webconsole/db.py