Skip to content

Commit

Permalink
Use the future flag on sessionmaker
Browse files Browse the repository at this point in the history
  • Loading branch information
martinburchell committed Jan 31, 2025
1 parent 7477c26 commit 0f2cf23
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion server/camcops_server/cc_modules/cc_anon.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def _gen_columns_for_anon_staging_db(
"""
url = SQLITE_MEMORY_URL
engine = create_engine(url, echo=False, future=True)
session = sessionmaker(bind=engine)() # type: SqlASession
session = sessionmaker(bind=engine)(future=True) # type: SqlASession
export_options = TaskExportOptions(
include_blobs=recipient.db_include_blobs,
db_patient_id_per_row=recipient.db_patient_id_per_row,
Expand Down
2 changes: 1 addition & 1 deletion server/camcops_server/cc_modules/cc_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1793,7 +1793,7 @@ def get_dbsession_raw(self) -> SqlASession:
"""
engine = self.get_sqla_engine()
maker = sessionmaker(bind=engine)
dbsession = maker() # type: SqlASession
dbsession = maker(future=True) # type: SqlASession
return dbsession

@contextlib.contextmanager
Expand Down
4 changes: 3 additions & 1 deletion server/camcops_server/cc_modules/cc_dummy_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ class DummyDataFactory(DummyDataInserter):
def __init__(self, cfg: "CamcopsConfig") -> None:
super().__init__()
engine = cfg.get_sqla_engine()
self.dbsession = sessionmaker()(bind=engine) # type: SqlASession
self.dbsession = sessionmaker()(
bind=engine, future=True
) # type: SqlASession

self.era_time = pendulum.now()
self.era_time_utc = convert_datetime_to_utc(self.era_time)
Expand Down
8 changes: 6 additions & 2 deletions server/camcops_server/cc_modules/cc_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,9 @@ def export_whole_database(
"Exporting to database: {}",
get_safe_url_from_engine(dst_engine),
)
dst_session = sessionmaker(bind=dst_engine)() # type: SqlASession
dst_session = sessionmaker(bind=dst_engine)(
future=True
) # type: SqlASession
task_generator = gen_tasks_having_exportedtasks(collection)
export_options = TaskExportOptions(
include_blobs=recipient.db_include_blobs,
Expand Down Expand Up @@ -1209,7 +1211,9 @@ def get_sqlite_data(self, as_text: bool) -> Union[bytes, str]:
# ---------------------------------------------------------------------
url = "sqlite:///" + db_filename
engine = create_engine(url, echo=False, future=True)
dst_session = sessionmaker(bind=engine)() # type: SqlASession
dst_session = sessionmaker(bind=engine)(
future=True
) # type: SqlASession
# ---------------------------------------------------------------------
# Iterate through tasks, creating tables as we need them.
# ---------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion server/camcops_server/cc_modules/cc_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ def get_bare_dbsession(self) -> SqlASession:
log.debug("Making SQLAlchemy session")
engine = self.engine
maker = sessionmaker(bind=engine)
session = maker() # type: SqlASession
session = maker(future=True) # type: SqlASession
return session

# -------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion server/playing/pyramid_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ def session_context():
cfg = get_config() # type: DummyConfig
engine = cfg.create_engine()
maker = sessionmaker(bind=engine)
dbsession = maker() # type: SqlASession
dbsession = maker(future=True) # type: SqlASession
# noinspection PyUnusedLocal,PyBroadException
try:
yield dbsession
Expand Down

0 comments on commit 0f2cf23

Please sign in to comment.