From 1f36e84b458da019cbaf92c02e279dfad279e65b Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Tue, 14 Nov 2023 08:38:48 -0500 Subject: [PATCH] Correctly handle case where unpartitioned table does not exist (#14648) --- awx/api/views/__init__.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index 0511b696645d..221db21b006d 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -128,6 +128,10 @@ def unpartitioned_event_horizon(cls): + with connection.cursor() as cursor: + cursor.execute(f"SELECT 1 FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '_unpartitioned_{cls._meta.db_table}';") + if not cursor.fetchone(): + return 0 with connection.cursor() as cursor: try: cursor.execute(f'SELECT MAX(id) FROM _unpartitioned_{cls._meta.db_table}')