From d05cd64097946bcfc8406d079a5f2da6dd9b0305 Mon Sep 17 00:00:00 2001 From: Jimmy Conner Date: Wed, 4 Sep 2024 23:03:52 -0500 Subject: [PATCH] Fix failing bulk launch job due to create partition race Courteously supplied by upstream PR 15000 --- awx/main/utils/common.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index a3760f5..25e0288 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -1,5 +1,6 @@ # Copyright (c) 2015 Ansible, Inc. # All Rights Reserved. +# Modifications Copyright (c) 2024 Ctrl IQ, Inc. # Python from datetime import timedelta @@ -1160,14 +1161,13 @@ def create_partition(tblname, start=None): except (ProgrammingError, IntegrityError) as e: cause = e.__cause__ if cause and hasattr(cause, 'sqlstate'): - # 42P07 = DuplicateTable sqlstate = cause.sqlstate - sqlstate_str = psycopg.errors.lookup(sqlstate) + sqlstate_cls = psycopg.errors.lookup(sqlstate) - if psycopg.errors.DuplicateTable == sqlstate: + if psycopg.errors.DuplicateTable == sqlstate_cls or psycopg.errors.UniqueViolation == sqlstate_cls: logger.info(f'Caught known error due to partition creation race: {e}') else: - logger.error('SQL Error state: {} - {}'.format(sqlstate, sqlstate_str)) + logger.error('SQL Error state: {} - {}'.format(sqlstate, sqlstate_cls)) raise except DatabaseError as e: cause = e.__cause__