diff --git a/CHANGELOG.md b/CHANGELOG.md index efc8e8a..5f444dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v0.0.8 - 20??-??-?? - ??? * Add support for optionally retrying requests that hit 403 errors +* Add a zone_id lookup fallback when deleting records ## v0.0.7 - 2024-08-20 - DS always come second diff --git a/octodns_cloudflare/__init__.py b/octodns_cloudflare/__init__.py index e9430df..8dbda3e 100644 --- a/octodns_cloudflare/__init__.py +++ b/octodns_cloudflare/__init__.py @@ -1176,6 +1176,7 @@ def _apply_Delete(self, change): existing_name = existing.fqdn[:-1] # Make sure to map ALIAS to CNAME when looking for the target to delete existing_type = 'CNAME' if existing._type == 'ALIAS' else existing._type + zone_id = self.zones[existing.zone.name] for record in self.zone_records(existing.zone): if 'targets' in record and self.pagerules: uri = record['targets'][0]['constraint']['value'] @@ -1183,7 +1184,6 @@ def _apply_Delete(self, change): parsed_uri = urlsplit(uri) record_name = parsed_uri.netloc record_type = 'URLFWD' - zone_id = self.zones.get(existing.zone.name, False) if ( existing_name == record_name and existing_type == record_type @@ -1195,8 +1195,16 @@ def _apply_Delete(self, change): existing_name == record['name'] and existing_type == record['type'] ): + record_zone_id = record.get('zone_id') + if record_zone_id is None: + self.log.warning( + '_apply_Delete: record "%s", %s is missing "zone_id", falling back to lookup', + record['name'], + record['type'], + ) + record_zone_id = zone_id path = ( - f'/zones/{record["zone_id"]}/dns_records/' + f'/zones/{record_zone_id}/dns_records/' f'{record["id"]}' ) self._try_request('DELETE', path) diff --git a/tests/test_octodns_provider_cloudflare.py b/tests/test_octodns_provider_cloudflare.py index 4536111..a654ae7 100644 --- a/tests/test_octodns_provider_cloudflare.py +++ b/tests/test_octodns_provider_cloudflare.py @@ -372,7 +372,6 @@ def test_apply(self): "proxied": False, "ttl": 300, "locked": False, - "zone_id": "ff12ab34cd5611334422ab3322997650", "zone_name": "unit.tests", "modified_on": "2017-03-11T18:01:43.420689Z", "created_on": "2017-03-11T18:01:43.420689Z", @@ -533,10 +532,10 @@ def test_apply(self): 'DELETE', '/zones/42/pagerules/2a9141b18ffb0e6aed826050eec970b8', ), + # this one used the zone_id lookup fallback, thus 42 call( 'DELETE', - '/zones/ff12ab34cd5611334422ab3322997650/' - 'dns_records/fc12ab34cd5611334422ab3322997653', + '/zones/42/dns_records/fc12ab34cd5611334422ab3322997653', ), call( 'DELETE',