55
66from sqlalchemy import select
77from sqlalchemy .ext .asyncio import AsyncSession
8- from sqlalchemy .orm import joinedload , lazyload , selectinload
8+ from sqlalchemy .orm import joinedload , lazyload , load_only , selectinload
99
1010from dstack ._internal .core .backends .base .backend import Backend
1111from dstack ._internal .core .backends .base .compute import ComputeWithVolumeSupport
@@ -120,6 +120,7 @@ async def _process_next_submitted_job():
120120 JobModel .status == JobStatus .SUBMITTED ,
121121 JobModel .id .not_in (lockset ),
122122 )
123+ .options (load_only (JobModel .id ))
123124 # Jobs are process in FIFO sorted by priority globally,
124125 # thus runs from different projects can "overtake" each other by using higher priorities.
125126 # That's not a big problem as long as projects do not compete for the same compute resources.
@@ -152,7 +153,6 @@ async def _process_next_submitted_job():
152153
153154
154155async def _process_submitted_job (session : AsyncSession , job_model : JobModel ):
155- logger .debug ("%s: provisioning has started" , fmt (job_model ))
156156 # Refetch to load related attributes.
157157 res = await session .execute (
158158 select (JobModel ).where (JobModel .id == job_model .id ).options (joinedload (JobModel .instance ))
@@ -166,6 +166,8 @@ async def _process_submitted_job(session: AsyncSession, job_model: JobModel):
166166 .options (joinedload (RunModel .fleet ).joinedload (FleetModel .instances ))
167167 )
168168 run_model = res .unique ().scalar_one ()
169+ logger .debug ("%s: provisioning has started" , fmt (job_model ))
170+
169171 project = run_model .project
170172 run = run_model_to_run (run_model )
171173 run_spec = run .run_spec
0 commit comments