From 2276d770d1ac7c8b6a8d2b7fb1af98d290e93911 Mon Sep 17 00:00:00 2001 From: Sven Luethi Date: Tue, 11 Aug 2026 10:59:48 +0200 Subject: [PATCH] Remove unreachable not-found branch in dns-export-zone The command loaded the zone with Zone.objects.get(...) and then tested the result for truthiness: nb_zone = Zone.objects.get(...) if nb_zone: ...export... else: self.stderr.write('Zone not found in Netbox. Aborting') Zone.objects.get() either returns a model instance (always truthy) or raises Zone.DoesNotExist. It never returns a falsy value, so the else branch was unreachable dead code. A missing zone is already handled correctly: DoesNotExist is a subclass of Exception, which the surrounding try/except catches and converts into a CommandError. Drop the dead if/else and call export_bind_zone_file directly. --- .../management/commands/dns-export-zone.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/netbox_dns_bridge/management/commands/dns-export-zone.py b/netbox_dns_bridge/management/commands/dns-export-zone.py index e2f3d9c..206cd6d 100644 --- a/netbox_dns_bridge/management/commands/dns-export-zone.py +++ b/netbox_dns_bridge/management/commands/dns-export-zone.py @@ -37,13 +37,10 @@ class Command(BaseCommand): view__name=view_name, name=zone_name ) - if nb_zone: - export_bind_zone_file(nb_zone, file_path=file_path) - self.stdout.write( - self.style.SUCCESS(f"Zone '{zone_name}' exported to '{file_path}'") - ) - else: - self.stderr.write("Zone not found in Netbox. Aborting") + export_bind_zone_file(nb_zone, file_path=file_path) + self.stdout.write( + self.style.SUCCESS(f"Zone '{zone_name}' exported to '{file_path}'") + ) except Exception as e: raise CommandError(f"Failed to export zone: {e}")