From 127a0cff23ace22615b33bfa9b488e5c23ed4042 Mon Sep 17 00:00:00 2001 From: Seth Foster Date: Wed, 4 Oct 2023 20:46:50 -0400 Subject: [PATCH] Set ip_address to empty string ip_address cannot be null, so set to empty instead of None Signed-off-by: Seth Foster --- awx/main/managers.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/awx/main/managers.py b/awx/main/managers.py index 706947657a..747f9d4467 100644 --- a/awx/main/managers.py +++ b/awx/main/managers.py @@ -125,14 +125,15 @@ class InstanceManager(models.Manager): with advisory_lock('instance_registration_%s' % hostname): if settings.AWX_AUTO_DEPROVISION_INSTANCES: # detect any instances with the same IP address. - # if one exists, set it to None - inst_conflicting_ip = self.filter(ip_address=ip_address).exclude(hostname=hostname) - if inst_conflicting_ip.exists(): - for other_inst in inst_conflicting_ip: - other_hostname = other_inst.hostname - other_inst.ip_address = None - other_inst.save(update_fields=['ip_address']) - logger.warning("IP address {0} conflict detected, ip address unset for host {1}.".format(ip_address, other_hostname)) + # if one exists, set it to "" + if ip_address: + inst_conflicting_ip = self.filter(ip_address=ip_address).exclude(hostname=hostname) + if inst_conflicting_ip.exists(): + for other_inst in inst_conflicting_ip: + other_hostname = other_inst.hostname + other_inst.ip_address = "" + other_inst.save(update_fields=['ip_address']) + logger.warning("IP address {0} conflict detected, ip address unset for host {1}.".format(ip_address, other_hostname)) # Return existing instance that matches hostname or UUID (default to UUID) if node_uuid is not None and node_uuid != UUID_DEFAULT and self.filter(uuid=node_uuid).exists():