Skip to content

Commit

Permalink
Delay Sqlalchemy import in DB trigger
Browse files Browse the repository at this point in the history
Since Sqlalchemy is only used server-side, it's an extraneous
dependency of the SDK-only install
  • Loading branch information
cjao committed May 25, 2024
1 parent 2df507c commit 1fa8ac9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions covalent/triggers/database_trigger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
from threading import Event
from typing import List

from sqlalchemy import create_engine
from sqlalchemy.orm import Session

from covalent._shared_files import logger

from .base import BaseTrigger
Expand Down Expand Up @@ -88,6 +85,12 @@ def observe(self) -> None:
where conditions are met or until stop has being called
"""

# Since these modules are only used server-side, delay their
# imports to avoid introducing a sqlalchemy requirement to
# SDK-only installs
from sqlalchemy import create_engine
from sqlalchemy.orm import Session

app_log.debug("Inside DatabaseTrigger's observe")
event_count = 0

Expand Down
4 changes: 2 additions & 2 deletions tests/covalent_tests/triggers/database_trigger_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def test_database_trigger_observe(mocker, where_clauses, database_trigger):
database_trigger.where_clauses = where_clauses
database_trigger.trigger = mocker.MagicMock()

mock_db_engine = mocker.patch("covalent.triggers.database_trigger.create_engine")
mock_session = mocker.patch("covalent.triggers.database_trigger.Session")
mock_db_engine = mocker.patch("sqlalchemy.create_engine")
mock_session = mocker.patch("sqlalchemy.orm.Session")
mock_event = mocker.patch("covalent.triggers.database_trigger.Event")
mock_sleep = mocker.patch("covalent.triggers.database_trigger.time.sleep")

Expand Down

0 comments on commit 1fa8ac9

Please sign in to comment.