Skip to content

Commit 84ecf66

Browse files
fix: avoid FOR UPDATE with outer join in process_idle_volumes (Postgres compatibility)
1 parent 6721cb7 commit 84ecf66

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/dstack/_internal/server/background/tasks/process_idle_volumes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
from sqlalchemy import select
55
from sqlalchemy.ext.asyncio import AsyncSession
6-
from sqlalchemy.orm import joinedload
76

87
from dstack._internal.core.models.profiles import parse_duration
98
from dstack._internal.core.models.volumes import VolumeStatus
@@ -31,13 +30,14 @@ async def process_idle_volumes(batch_size: int = 10):
3130
VolumeModel.deleted == False,
3231
VolumeModel.id.not_in(lockset),
3332
)
34-
.options(joinedload(VolumeModel.project))
35-
.options(joinedload(VolumeModel.attachments))
3633
.order_by(VolumeModel.last_processed_at.asc())
3734
.limit(batch_size)
3835
.with_for_update(skip_locked=True)
3936
)
4037
volume_models = list(res.unique().scalars().all())
38+
# Manually load relationships to avoid outer join in the locked query
39+
for volume_model in volume_models:
40+
await session.refresh(volume_model, ["project", "attachments"])
4141
if not volume_models:
4242
return
4343

0 commit comments

Comments
 (0)