mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-12 19:38:57 +00:00
Fix issues with latest version of sqlalchemy
This commit is contained in:
parent
4727708c85
commit
956b9056c1
@ -43,6 +43,7 @@ class GUID(TypeDecorator):
|
||||
"""
|
||||
|
||||
impl = CHAR
|
||||
cache_ok = True
|
||||
|
||||
def load_dialect_impl(self, dialect):
|
||||
if dialect.name == "postgresql":
|
||||
|
@ -43,12 +43,12 @@ async def connect_to_db(app: FastAPI) -> None:
|
||||
db_url = os.environ.get("GNS3_DATABASE_URI", f"sqlite+aiosqlite:///{db_path}")
|
||||
engine = create_async_engine(db_url, connect_args={"check_same_thread": False}, future=True)
|
||||
try:
|
||||
async with engine.begin() as conn:
|
||||
async with engine.connect() as conn:
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
log.info(f"Successfully connected to database '{db_url}'")
|
||||
app.state._db_engine = engine
|
||||
except SQLAlchemyError as e:
|
||||
log.error(f"Error while connecting to database '{db_url}: {e}")
|
||||
log.fatal(f"Error while connecting to database '{db_url}: {e}")
|
||||
|
||||
|
||||
@event.listens_for(Engine, "connect")
|
||||
|
@ -78,7 +78,7 @@ async def db_session(db_engine):
|
||||
# recreate database tables for each class
|
||||
# preferred and faster way would be to rollback the session/transaction
|
||||
# but it doesn't work for some reason
|
||||
async with db_engine.begin() as conn:
|
||||
async with db_engine.connect() as conn:
|
||||
# Speed up tests by avoiding to hash the 'admin' password everytime the default super admin is added
|
||||
# to the database using the "after_create" sqlalchemy event
|
||||
hashed_password = "$2b$12$jPsNU9IS7.EWEqXahtDfo.26w6VLOLCuFEHKNvDpOjxs5e0WpqJfa"
|
||||
@ -86,7 +86,7 @@ async def db_session(db_engine):
|
||||
await conn.run_sync(Base.metadata.drop_all)
|
||||
await conn.run_sync(Base.metadata.create_all)
|
||||
|
||||
session = AsyncSession(db_engine)
|
||||
session = AsyncSession(db_engine, expire_on_commit=False)
|
||||
try:
|
||||
yield session
|
||||
finally:
|
||||
|
Loading…
Reference in New Issue
Block a user