From 82f1e2cc61ede47f8d249a946f13bcfc8a854a29 Mon Sep 17 00:00:00 2001 From: David O Neill Date: Wed, 21 Feb 2024 18:44:31 +0000 Subject: [PATCH] English string validation to error code validation --- awx/main/tasks/system.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/awx/main/tasks/system.py b/awx/main/tasks/system.py index 4ebe1d576612..84f096d5e665 100644 --- a/awx/main/tasks/system.py +++ b/awx/main/tasks/system.py @@ -6,6 +6,7 @@ import json import logging import os +import psycopg from io import StringIO from contextlib import redirect_stdout import shutil @@ -630,10 +631,15 @@ def cluster_node_heartbeat(dispatch_time=None, worker_tasks=None): logger.error("Host {} last checked in at {}, marked as lost.".format(other_inst.hostname, other_inst.last_seen)) except DatabaseError as e: - if 'did not affect any rows' in str(e): - logger.debug('Another instance has marked {} as lost'.format(other_inst.hostname)) + if hasattr(e, 'sqlstate'): + sqlstate = e.sqlstate + + if sqlstate == psycopg.errors.NoData: + logger.debug('Another instance has marked {} as lost'.format(other_inst.hostname)) + else: + logger.exception("Unhandled error with SQL state: {}".format(sqlstate)) else: - logger.exception('Error marking {} as lost'.format(other_inst.hostname)) + logger.exception('No SQL state available. Error marking {} as lost'.format(other_inst.hostname)) # Run local reaper if worker_tasks is not None: