Merge pull request #9738 from beeankha/update_schedule_sort

Enable ?page_size=1 to Fetch Correct Objects on JT Endpoint

SUMMARY

Problem:
When multiple schedules are made from a single JT and a URL sort is done via:
api/v2/job_templates/[id]/schedules/?page_size=1
... the first half of the results come back with the same ID. 🤔
Solution:
Implementing a backup sort via ID on the schedules model fixes this problem, and now all schedules on the job template endpoint are being fetched properly.

ISSUE TYPE


Bugfix Pull Request

COMPONENT NAME


API

AWX VERSION

awx: 18.0.0

ADDITIONAL INFORMATION

This might fix #9632

Reviewed-by: Seth Foster <None>
Reviewed-by: Rebeccah Hunter <rhunter@redhat.com>
This commit is contained in:
softwarefactory-project-zuul[bot] 2021-03-29 19:03:33 +00:00 committed by GitHub
commit 94eeea6c33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 2.2.16 on 2021-03-29 15:30
from django.db import migrations
import django.db.models.expressions
class Migration(migrations.Migration):
dependencies = [
('main', '0134_unifiedjob_ansible_version'),
]
operations = [
migrations.AlterModelOptions(
name='schedule',
options={'ordering': [django.db.models.expressions.OrderBy(django.db.models.expressions.F('next_run'), descending=True, nulls_last=True), 'id']},
),
]

View File

@ -63,7 +63,7 @@ class ScheduleManager(ScheduleFilterMethods, models.Manager):
class Schedule(PrimordialModel, LaunchTimeConfig):
class Meta:
app_label = 'main'
ordering = ['-next_run']
ordering = [models.F('next_run').desc(nulls_last=True), 'id']
unique_together = ('unified_job_template', 'name')
objects = ScheduleManager()