diff --git a/changes/372.fixed b/changes/372.fixed new file mode 100644 index 00000000..c30d9e30 --- /dev/null +++ b/changes/372.fixed @@ -0,0 +1 @@ +Fixed bug when loading Nautobot Vlans with multiple locations assigned. Only Vlans with 1 location will be considered for the sync. \ No newline at end of file diff --git a/nautobot_device_onboarding/diffsync/adapters/sync_network_data_adapters.py b/nautobot_device_onboarding/diffsync/adapters/sync_network_data_adapters.py index 316f7dcb..8b9c89c6 100644 --- a/nautobot_device_onboarding/diffsync/adapters/sync_network_data_adapters.py +++ b/nautobot_device_onboarding/diffsync/adapters/sync_network_data_adapters.py @@ -134,7 +134,15 @@ def load_vlans(self): """ # TODO: update this to support multiple locations per VLAN after the setting for this feature has been added. location_ids = list(self.job.devices_to_load.values_list("location__id", flat=True)) - for vlan in VLAN.objects.filter(location__in=location_ids): + for vlan in VLAN.objects.filter(locations__in=location_ids): + if ( + vlan.locations.count() > 1 + ): # TODO: A conditional check will be needed here to support multiple locations per VLAN + if self.job.debug: + self.job.logger.debug( + f"Vlan {vlan.name} has multiple locations. Skipping Vlan load for {vlan.name}." + ) + continue network_vlan = self.vlan( adapter=self, name=vlan.name,