Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove scoped session since fastapi reuse threads, breaking thread local sessions #283

Merged
merged 1 commit into from
Jan 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/regtech_user_fi_management/entities/engine/engine.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import scoped_session, sessionmaker
from sqlalchemy.orm import sessionmaker
from regtech_user_fi_management.config import settings

engine = create_engine(str(settings.inst_conn), echo=settings.db_logging).execution_options(
schema_translate_map={None: settings.inst_db_schema}
)
SessionLocal = scoped_session(sessionmaker(engine, expire_on_commit=False))
SessionLocal = Session = sessionmaker(engine, expire_on_commit=False)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adding the Session name as a more syntactically correct term since it's not thread local anymore; clean up to remove SessionLocal later after downstream repos use the new term



def get_session():
session = SessionLocal()
try:
with Session() as session:
yield session
finally:
session.close()
Loading