diff --git a/designate/api/v1/records.py b/designate/api/v1/records.py index b7375c11b..a6e9b3f1c 100644 --- a/designate/api/v1/records.py +++ b/designate/api/v1/records.py @@ -46,9 +46,7 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl): central_api.find_domain(context, criterion=criterion) try: - recordset = _find_recordset(context, domain_id, name, type) - except exceptions.RecordSetNotFound: - # Create an empty recordset + # Attempt to create an empty recordset values = { 'name': name, 'type': type, @@ -58,6 +56,10 @@ def _find_or_create_recordset(context, domain_id, name, type, ttl): recordset = central_api.create_recordset( context, domain_id, objects.RecordSet(**values)) + except exceptions.DuplicateRecordSet: + # Fetch the existing recordset + recordset = _find_recordset(context, domain_id, name, type) + return recordset diff --git a/designate/notification_handler/base.py b/designate/notification_handler/base.py index f43985aad..993141e53 100644 --- a/designate/notification_handler/base.py +++ b/designate/notification_handler/base.py @@ -69,12 +69,7 @@ class NotificationHandler(ExtensionPlugin): name = name.encode('idna') try: - recordset = self.central_api.find_recordset(context, { - 'domain_id': domain_id, - 'name': name, - 'type': type, - }) - except exceptions.RecordSetNotFound: + # Attempt to create an empty recordset values = { 'name': name, 'type': type, @@ -83,6 +78,14 @@ class NotificationHandler(ExtensionPlugin): recordset = self.central_api.create_recordset( context, domain_id, RecordSet(**values)) + except exceptions.DuplicateRecordSet: + # Fetch the existing recordset + recordset = self.central_api.find_recordset(context, { + 'domain_id': domain_id, + 'name': name, + 'type': type, + }) + return recordset