Only create receptor address if port is defined

If a Instance endpoint is patched with
{"peers_from_control_nodes" True}

but a listener_port is not defined on the instance,
or is part of the patch payload, do not create a
receptor address.

Only update or create a receptor address if listener_port
is set, either in the payload or already on the instance.

Signed-off-by: Seth Foster <fosterbseth@gmail.com>
This commit is contained in:
Seth Foster
2024-01-18 13:56:35 -05:00
committed by Seth Foster
parent 73d2c92ae3
commit dbfcc40d7c
2 changed files with 51 additions and 33 deletions

View File

@@ -5609,10 +5609,14 @@ class InstanceSerializer(BaseSerializer):
else:
instance = super(InstanceSerializer, self).update(obj, validated_data)
# delete the receptor address if the port is expolisitly set to None
if 'port' in kwargs and not kwargs['port']:
# delete the receptor address if the port is expolisitly set to None
instance.receptor_addresses.filter(address=instance.hostname).delete()
elif 'port' in kwargs:
# only create or update if port is defined in validated_data or already exists in the
# canonical address
# this prevents creating a receptor address if peers_from_control_nodes is in
# validated_data but a port is not set
elif kwargs and ('port' in kwargs or instance.canonical_address_port):
kwargs['canonical'] = True
instance.receptor_addresses.update_or_create(address=instance.hostname, defaults=kwargs)