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__