Skip to content

Commit

Permalink
Fix failing bulk launch job due to create partition race
Browse files Browse the repository at this point in the history
Courteously supplied by upstream PR 15000
  • Loading branch information
cigamit committed Sep 5, 2024
1 parent fe913a2 commit d05cd64
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions awx/main/utils/common.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved.
# Modifications Copyright (c) 2024 Ctrl IQ, Inc.

# Python
from datetime import timedelta
Expand Down Expand Up @@ -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__
Expand Down

0 comments on commit d05cd64

Please sign in to comment.