From 6c1d4a5cfdd8dc9552a8e7a0534c3a259764b11f Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Sat, 4 Feb 2023 12:10:39 -0500 Subject: [PATCH 1/2] Skip callback receiver bulk_create with 0 events --- awx/main/dispatch/worker/callback.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/awx/main/dispatch/worker/callback.py b/awx/main/dispatch/worker/callback.py index b0588265a4..e1db0f27e9 100644 --- a/awx/main/dispatch/worker/callback.py +++ b/awx/main/dispatch/worker/callback.py @@ -154,6 +154,8 @@ class CallbackBrokerWorker(BaseWorker): metrics_events_missing_created = 0 metrics_total_job_event_processing_seconds = datetime.timedelta(seconds=0) for cls, events in self.buff.items(): + if not events: + continue logger.debug(f'{cls.__name__}.objects.bulk_create({len(events)})') for e in events: e.modified = now # this can be set before created because now is set above on line 149 From 51112b95bcc587c14a9f8838c0407f9909de9992 Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Sun, 5 Feb 2023 22:46:50 -0500 Subject: [PATCH 2/2] Add test for callback events flush with nothing in the buffer --- .../tests/functional/commands/test_callback_receiver.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/awx/main/tests/functional/commands/test_callback_receiver.py b/awx/main/tests/functional/commands/test_callback_receiver.py index 234392fb44..7b9346fe73 100644 --- a/awx/main/tests/functional/commands/test_callback_receiver.py +++ b/awx/main/tests/functional/commands/test_callback_receiver.py @@ -116,6 +116,13 @@ class TestCallbackBrokerWorker(TransactionTestCase): assert worker.buff.get(InventoryUpdateEvent, []) == [] assert InventoryUpdateEvent.objects.filter(uuid=events[0].uuid).count() == 0 # sanity + def test_flush_with_empty_buffer(self): + worker = self.get_worker() + worker.buff = {InventoryUpdateEvent: []} + with mock.patch.object(InventoryUpdateEvent.objects, 'bulk_create') as flush_mock: + worker.flush() + flush_mock.assert_not_called() + def test_postgres_invalid_NUL_char(self): # In postgres, text fields reject NUL character, 0x00 # tests use sqlite3 which will not raise an error