From d22291371628cdfe725351d19cebfed7749f7df4 Mon Sep 17 00:00:00 2001 From: Jad Seifeddine <144011572+jseifeddine@users.noreply.github.com> Date: Tue, 5 Aug 2025 00:15:05 +1000 Subject: [PATCH] Fixes: #19917 - Fix MAC address pagination duplicates by adding 'pk' to model ordering (#19961) * Fix MAC address pagination duplicates by adding 'pk' to model ordering Add 'pk' to MACAddress model ordering to ensure deterministic results when multiple MAC addresses have the same value. This prevents the same MAC address from appearing on multiple pages during pagination. The issue occurred because Django's default ordering by 'mac_address' alone is non-deterministic when multiple records share the same MAC address value, causing inconsistent pagination results when the same MAC address is assigned to multiple interfaces on a device. Added regression test that verifies MAC addresses with identical values are properly ordered by their primary key, ensuring consistent pagination behavior across the application. Fixes netbox-community#19917 * Remove test * Resolve migration conflict --------- Co-authored-by: Jad Seifeddine Co-authored-by: Jeremy Stretch --- .../migrations/0210_macaddress_ordering.py | 19 +++++++++++++++++++ netbox/dcim/models/devices.py | 2 +- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 netbox/dcim/migrations/0210_macaddress_ordering.py diff --git a/netbox/dcim/migrations/0210_macaddress_ordering.py b/netbox/dcim/migrations/0210_macaddress_ordering.py new file mode 100644 index 000000000..5d719c5ad --- /dev/null +++ b/netbox/dcim/migrations/0210_macaddress_ordering.py @@ -0,0 +1,19 @@ +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('dcim', '0209_device_component_denorm_site_location'), + ] + + operations = [ + migrations.AlterModelOptions( + name='macaddress', + options={ + 'ordering': ('mac_address', 'pk'), + 'verbose_name': 'MAC address', + 'verbose_name_plural': 'MAC addresses' + }, + ), + ] diff --git a/netbox/dcim/models/devices.py b/netbox/dcim/models/devices.py index abd29d4e3..e1ad9c15c 100644 --- a/netbox/dcim/models/devices.py +++ b/netbox/dcim/models/devices.py @@ -1276,7 +1276,7 @@ class MACAddress(PrimaryModel): ) class Meta: - ordering = ('mac_address',) + ordering = ('mac_address', 'pk',) verbose_name = _('MAC address') verbose_name_plural = _('MAC addresses')