From d0d467e863b600644a692ffd80a7dded60282387 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Wed, 30 Nov 2022 10:03:11 -0500 Subject: [PATCH] Fix a problem with migration main/0164 Since the original version of the migration a) invoked the .save() method, and b) involved a model with a custom field that had a post_save handler attached, this migration had a side-effect that caused the codebase's version of the model to be used when the table involved wasn't yet up to date. This triggers an UndefinedColumn error. This change works around the problem by making use of queryset .update() methods instead, which should avoid the post_save signal trigger. --- ...inventorysource_update_on_project_update.py | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/awx/main/migrations/0164_remove_inventorysource_update_on_project_update.py b/awx/main/migrations/0164_remove_inventorysource_update_on_project_update.py index 59c4bdf839..9ccc5156e0 100644 --- a/awx/main/migrations/0164_remove_inventorysource_update_on_project_update.py +++ b/awx/main/migrations/0164_remove_inventorysource_update_on_project_update.py @@ -1,24 +1,14 @@ # Generated by Django 3.2.13 on 2022-06-21 21:29 from django.db import migrations -import logging - -logger = logging.getLogger("awx") def forwards(apps, schema_editor): InventorySource = apps.get_model('main', 'InventorySource') - sources = InventorySource.objects.filter(update_on_project_update=True) - for src in sources: - if src.update_on_launch == False: - src.update_on_launch = True - src.save(update_fields=['update_on_launch']) - logger.info(f"Setting update_on_launch to True for {src}") - proj = src.source_project - if proj and proj.scm_update_on_launch is False: - proj.scm_update_on_launch = True - proj.save(update_fields=['scm_update_on_launch']) - logger.warning(f"Setting scm_update_on_launch to True for {proj}") + InventorySource.objects.filter(update_on_project_update=True).update(update_on_launch=True) + + Project = apps.get_model('main', 'Project') + Project.objects.filter(scm_inventory_sources__update_on_project_update=True).update(scm_update_on_launch=True) class Migration(migrations.Migration):