summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--awx/main/dispatch/worker/callback.py2
-rw-r--r--awx/main/tests/functional/commands/test_callback_receiver.py7
2 files changed, 9 insertions, 0 deletions
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
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