Skip to content

Commit 196d9a9

Browse files
hieheiheiLawrenceZHLee
authored andcommitted
refactor: Use Repository Pattern for Model Layer (langgenius#27663)
1 parent 8aed550 commit 196d9a9

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

api/models/model.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,13 @@ def message_files(self) -> list[dict[str, Any]]:
12191219
@property
12201220
def workflow_run(self):
12211221
if self.workflow_run_id:
1222-
from .workflow import WorkflowRun
1222+
from sqlalchemy.orm import sessionmaker
12231223

1224-
return db.session.query(WorkflowRun).where(WorkflowRun.id == self.workflow_run_id).first()
1224+
from repositories.factory import DifyAPIRepositoryFactory
1225+
1226+
session_maker = sessionmaker(bind=db.engine, expire_on_commit=False)
1227+
repo = DifyAPIRepositoryFactory.create_api_workflow_run_repository(session_maker)
1228+
return repo.get_workflow_run_by_id_without_tenant(run_id=self.workflow_run_id)
12251229

12261230
return None
12271231

api/models/workflow.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,16 @@ class WorkflowAppLog(Base):
10581058

10591059
@property
10601060
def workflow_run(self):
1061-
return db.session.get(WorkflowRun, self.workflow_run_id)
1061+
if self.workflow_run_id:
1062+
from sqlalchemy.orm import sessionmaker
1063+
1064+
from repositories.factory import DifyAPIRepositoryFactory
1065+
1066+
session_maker = sessionmaker(bind=db.engine, expire_on_commit=False)
1067+
repo = DifyAPIRepositoryFactory.create_api_workflow_run_repository(session_maker)
1068+
return repo.get_workflow_run_by_id_without_tenant(run_id=self.workflow_run_id)
1069+
1070+
return None
10621071

10631072
@property
10641073
def created_by_account(self):

0 commit comments

Comments
 (0)