-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Kedro in Azure ML with SQLiteSessionStore (#2131)
* Update database.py Signed-off-by: Sajid Alam <[email protected]> * Update database.py Signed-off-by: Sajid Alam <[email protected]> * Update database.py Signed-off-by: Sajid Alam <[email protected]> * Update database.py Signed-off-by: Sajid Alam <[email protected]> * Update database.py Signed-off-by: Sajid Alam <[email protected]> * Update database.py Signed-off-by: Sajid Alam <[email protected]> * lint Signed-off-by: Sajid Alam <[email protected]> * add test Signed-off-by: Sajid Alam <[email protected]> * Update database.py Signed-off-by: Sajid Alam <[email protected]> * revert comments Signed-off-by: Sajid Alam <[email protected]> * separate azure logic Signed-off-by: Sajid Alam <[email protected]> * Update RELEASE.md Signed-off-by: Sajid Alam <[email protected]> * Update RELEASE.md Signed-off-by: Sajid Alam <[email protected]> --------- Signed-off-by: Sajid Alam <[email protected]> Signed-off-by: Sajid Alam <[email protected]>
- Loading branch information
1 parent
2eb18d9
commit 9996c99
Showing
3 changed files
with
47 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,41 @@ | ||
"""Database management layer based on SQLAlchemy""" | ||
|
||
from sqlalchemy import create_engine | ||
import os | ||
|
||
from sqlalchemy import create_engine, text | ||
from sqlalchemy.orm import sessionmaker | ||
|
||
from kedro_viz.models.experiment_tracking import Base | ||
|
||
|
||
def configure_wal_for_azure(engine): | ||
"""Applies WAL mode to SQLite if running in an Azure ML environment.""" | ||
is_azure_ml = any( | ||
var in os.environ | ||
for var in [ | ||
"AZUREML_ARM_SUBSCRIPTION", | ||
"AZUREML_ARM_RESOURCEGROUP", | ||
"AZUREML_RUN_ID", | ||
] | ||
) | ||
if is_azure_ml: | ||
with engine.connect() as conn: | ||
conn.execute(text("PRAGMA journal_mode=WAL;")) | ||
|
||
|
||
def make_db_session_factory(session_store_location: str) -> sessionmaker: | ||
"""SQLAlchemy connection to a SQLite DB""" | ||
database_url = f"sqlite:///{session_store_location}" | ||
engine = create_engine(database_url, connect_args={"check_same_thread": False}) | ||
session_class = sessionmaker(engine) | ||
# TODO: making db session factory shouldn't depend on models. | ||
# So want to move the table creation elsewhere ideally. | ||
# But this means returning engine as well as session class. | ||
|
||
# Check if we are running in an Azure ML environment if so enable WAL mode. | ||
configure_wal_for_azure(engine) | ||
|
||
# Create the database tables if they do not exist. | ||
Base.metadata.create_all(bind=engine) | ||
return session_class | ||
|
||
# Return a session factory bound to the engine. | ||
return sessionmaker(bind=engine) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters