AAP-57614 fix: also write installed_collections directly to DB

save_indirect_host_entries calls fetch_job_event_query which reads
job.installed_collections from the DB. When dispatched from
artifacts_handler, installed_collections was still only in
delay_update (not yet flushed to DB), so the task found no matching
EventQuery records and created no IndirectManagedNodeAudit entries.

Write both event_queries_processed and installed_collections directly
to the DB before dispatching, so save_indirect_host_entries has all
the data it needs immediately.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Dirk Julich
2026-03-20 17:58:59 +01:00
parent 21e73cb065
commit 96bd35bfb4

View File

@@ -301,14 +301,19 @@ class RunnerCallback:
else: else:
logger.warning(f'The file {COLLECTION_FILENAME} unexpectedly did not contain ansible_version') logger.warning(f'The file {COLLECTION_FILENAME} unexpectedly did not contain ansible_version')
# Write event_queries_processed=False directly to the DB rather # Write event_queries_processed and installed_collections directly
# than using delay_update, because delay_update only writes when # to the DB rather than using delay_update alone. delay_update
# the final job status is saved. save_indirect_host_entries # only writes when the final job status is saved, but
# checks this column under select_for_update and would bail out # save_indirect_host_entries needs both values in the DB
# if it still saw the default (True). # immediately: event_queries_processed=False to pass the
# select_for_update gate, and installed_collections to find
# matching EventQuery records via fetch_job_event_query.
from awx.main.models import Job from awx.main.models import Job
Job.objects.filter(id=self.instance.id).update(event_queries_processed=False) db_updates = {'event_queries_processed': False}
if 'installed_collections' in query_file_contents:
db_updates['installed_collections'] = query_file_contents['installed_collections']
Job.objects.filter(id=self.instance.id).update(**db_updates)
# Dispatch save_indirect_host_entries to process the EventQuery # Dispatch save_indirect_host_entries to process the EventQuery
# records created above. handle_success_and_failure_notifications # records created above. handle_success_and_failure_notifications