Skip to content

Commit f1082b2

Browse files
committed
Add explicit 'sorted_revisions()' call and replace all uses of 'revisions.all()' with it for 'LandingJob'
1 parent c52e80b commit f1082b2

File tree

4 files changed

+6
-3
lines changed

4 files changed

+6
-3
lines changed

src/lando/api/legacy/workers/landing_worker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def run_job(
300300
return True
301301

302302
# Run through the patches one by one and try to apply them.
303-
for revision in job.revisions.all():
303+
for revision in job.sorted_revisions():
304304
patch_buf = StringIO(revision.patch_string)
305305

306306
try:

src/lando/api/tests/test_landings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -879,4 +879,4 @@ def test_landing_job_revisions_sorting(
879879
job.sort_revisions(new_ordering)
880880
job.save()
881881
job = LandingJob.objects.get(id=job.id)
882-
assert list(job.revisions.all()) == new_ordering
882+
assert list(job.sorted_revisions()) == new_ordering

src/lando/main/management/commands/landing_worker.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def run_job(self, job: LandingJob) -> bool:
7272
repo.reset()
7373
repo.pull()
7474

75-
for revision in job.revisions.all():
75+
for revision in job.sorted_revisions():
7676
patch_buffer = StringIO(revision.patch)
7777
repo.apply_patch(patch_buffer)
7878

src/lando/main/models/landing_job.py

+3
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ def sort_revisions(self, revisions: list[Revision]):
246246
revision=revision, landing_job=self
247247
).update(index=index)
248248

249+
def sorted_revisions(self):
250+
return self.revisions.all().order_by('revisionlandingjob__index')
251+
249252
def set_landed_revision_diffs(self):
250253
"""Assign diff_ids, if available, to each association row."""
251254
# Update association table records with current diff_id values.

0 commit comments

Comments
 (0)