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 <jseifeddine@macquarietelecom.com>
Co-authored-by: Jeremy Stretch <jstretch@netboxlabs.com>
This commit is contained in:
Jad Seifeddine 2025-08-05 00:15:05 +10:00 committed by GitHub
parent 2c09973e01
commit d222913716
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -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'
},
),
]

View File

@ -1276,7 +1276,7 @@ class MACAddress(PrimaryModel):
) )
class Meta: class Meta:
ordering = ('mac_address',) ordering = ('mac_address', 'pk',)
verbose_name = _('MAC address') verbose_name = _('MAC address')
verbose_name_plural = _('MAC addresses') verbose_name_plural = _('MAC addresses')