From af900c8370ab9cdb8a2e364778df948a7ea3e673 Mon Sep 17 00:00:00 2001 From: Peter Braun Date: Tue, 17 Sep 2024 13:37:35 +0200 Subject: [PATCH] fix: maintain order of insertions into m2m relationship tables (#15536) --- awx/main/fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/awx/main/fields.py b/awx/main/fields.py index 49895d70fc3f..7a74aadb3c3c 100644 --- a/awx/main/fields.py +++ b/awx/main/fields.py @@ -1039,7 +1039,7 @@ def _update_m2m_position(self, sender, instance, action, **kwargs): descriptor = getattr(instance, self.name) order_with_respect_to = descriptor.source_field_name - for i, ig in enumerate(sender.objects.filter(**{order_with_respect_to: instance.pk})): + for i, ig in enumerate(sender.objects.filter(**{order_with_respect_to: instance.pk}).order_by('id')): if ig.position != i: ig.position = i ig.save()