From a6354450829461c30240dbe3e5d1eb0e7c398f2c Mon Sep 17 00:00:00 2001 From: Hao Liu <44379968+TheRealHaoLiu@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:11:35 -0400 Subject: [PATCH] Fix failing bulk launch job due to create partition race https://github.com/ansible/awx/pull/14910/files introduced a bug where we no longer accept the right exceptions when 2 job launch at the sametime and try to create jobevent table partition 1 of the job will fail --- awx/main/utils/common.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/awx/main/utils/common.py b/awx/main/utils/common.py index a3760f5e60..bdd7465b90 100644 --- a/awx/main/utils/common.py +++ b/awx/main/utils/common.py @@ -1160,14 +1160,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__