From 7d97ad021f633261e5222269127f3538b462fe0e Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Tue, 13 Jul 2021 13:40:44 -0400 Subject: [PATCH 1/3] Revert "Development of patch for inventory source migration error" This reverts commit 8772ca2e3a7c733f9594811eefc1010a8650e172. --- awx/main/migrations/_inventory_source.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/awx/main/migrations/_inventory_source.py b/awx/main/migrations/_inventory_source.py index ef0befdade..e6a65a82d4 100644 --- a/awx/main/migrations/_inventory_source.py +++ b/awx/main/migrations/_inventory_source.py @@ -1,7 +1,6 @@ import logging from django.utils.encoding import smart_text -from django.utils.timezone import now from awx.main.utils.common import set_current_apps from awx.main.utils.common import parse_yaml_or_json @@ -97,21 +96,6 @@ def delete_custom_inv_source(apps, schema_editor): set_current_apps(apps) InventorySource = apps.get_model('main', 'InventorySource') InventoryUpdate = apps.get_model('main', 'InventoryUpdate') - Schedule = apps.get_model('main', 'Schedule') - - saved_time = now() - - # We cannot allow polymorphic.SET_NULL relationships to exist before we delete any InventorySources or InventoryUpdates or Schedules - # so we do this hack of updating modified time so we can keep track of which schedules to delete (b/c we nulled the relationships) - Schedule.objects.filter(unified_job_template__inventorysource__source='custom').update(modified=saved_time) - InventoryUpdate.objects.filter(source='custom', schedule__isnull=False).update(schedule=None) - InventorySource.objects.filter(source='custom', next_schedule__isnull=False).update(next_schedule=None) - - # safe to delete Schedule objects with no schedule or next_schedule pointers from UJ or UJT tables - ct, deletions = Schedule.objects.filter(modified=saved_time).delete() - if ct: - logger.info('deleted {} custom inventory source schedules: {}'.format(ct, deletions)) - ct, deletions = InventoryUpdate.objects.filter(source='custom').delete() if ct: logger.info('deleted {}'.format((ct, deletions))) From d0d9266dd1c02cd99743d5d91ace7018c838140d Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Tue, 13 Jul 2021 13:41:36 -0400 Subject: [PATCH 2/3] Revert "Null iso IG jobs before deleting (#5122)" This reverts commit 1831b2591a2bf87e442af8c9a718c993560635d2. --- awx/main/migrations/0139_isolated_removal.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/awx/main/migrations/0139_isolated_removal.py b/awx/main/migrations/0139_isolated_removal.py index 024fd23ccb..0db16b6348 100644 --- a/awx/main/migrations/0139_isolated_removal.py +++ b/awx/main/migrations/0139_isolated_removal.py @@ -11,11 +11,8 @@ def remove_iso_instances(apps, schema_editor): def remove_iso_groups(apps, schema_editor): InstanceGroup = apps.get_model('main', 'InstanceGroup') - UnifiedJob = apps.get_model('main', 'UnifiedJob') with transaction.atomic(): - for ig in InstanceGroup.objects.filter(controller__isnull=False): - UnifiedJob.objects.filter(instance_group=ig).update(instance_group=None) - ig.delete() + InstanceGroup.objects.filter(controller__isnull=False).delete() class Migration(migrations.Migration): From b0c511a7a25a8219b09d4953b8bb40ca293a8edd Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Tue, 13 Jul 2021 11:36:20 -0400 Subject: [PATCH 3/3] Make non-polymorphic refs that slip through still work with our SET_NULL --- awx/main/utils/polymorphic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/awx/main/utils/polymorphic.py b/awx/main/utils/polymorphic.py index 28f8a11187..a821ffeb10 100644 --- a/awx/main/utils/polymorphic.py +++ b/awx/main/utils/polymorphic.py @@ -15,4 +15,6 @@ def build_polymorphic_ctypes_map(cls): def SET_NULL(collector, field, sub_objs, using): - return models.SET_NULL(collector, field, sub_objs.non_polymorphic(), using) + if hasattr(sub_objs, 'non_polymorphic'): + sub_objs = sub_objs.non_polymorphic() + return models.SET_NULL(collector, field, sub_objs, using)