-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Fixes: #19917 - Fix MAC address pagination duplicates by adding 'pk' to model ordering #19961
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes: #19917 - Fix MAC address pagination duplicates by adding 'pk' to model ordering #19961
Conversation
357a7b9 to
29b0285
Compare
3ad83da to
83b312a
Compare
|
Thanks @DanSheps Done jseifeddine@83b312a |
sorry, just saw the failed builds, |
83b312a to
d0331ee
Compare
|
should be good to go... thanks |
d0331ee to
14e2028
Compare
|
Cleaned up the tests and able to reproduce in both System check identified no issues (0 silenced).
test_mac_address_pagination_duplicates (dcim.tests.test_filtersets.MACAddressTestCase.test_mac_address_pagination_duplicates) ... FAIL
test_mac_address_pagination_duplicates (dcim.tests.test_api.MACAddressTest.test_mac_address_pagination_duplicates) ... FAIL
======================================================================
FAIL: test_mac_address_pagination_duplicates (dcim.tests.test_filtersets.MACAddressTestCase.test_mac_address_pagination_duplicates)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/netbox/netbox/dcim/tests/test_filtersets.py", line 6959, in test_mac_address_pagination_duplicates
self.assertEqual(len(all_ids & page_ids), 0)
AssertionError: 1 != 0
======================================================================
FAIL: test_mac_address_pagination_duplicates (dcim.tests.test_api.MACAddressTest.test_mac_address_pagination_duplicates)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/netbox/netbox/dcim/tests/test_api.py", line 2696, in test_mac_address_pagination_duplicates
self.assertEqual(len(all_mac_ids & page_ids), 0)
AssertionError: 1 != 0
----------------------------------------------------------------------
Ran 2 tests in 0.271s
FAILED (failures=2)with the proposed test_mac_address_pagination_duplicates (dcim.tests.test_filtersets.MACAddressTestCase.test_mac_address_pagination_duplicates) ... ok
test_mac_address_pagination_duplicates (dcim.tests.test_api.MACAddressTest.test_mac_address_pagination_duplicates) ... ok
----------------------------------------------------------------------
Ran 2 tests in 0.421s
OK |
fb76b55 to
d151401
Compare
|
I've removed the tests completely just keeping the actual fix, |
d151401 to
2043bdc
Compare
|
I added the appropriate test, with 10 identical mac address values; It now fails without the Test that MAC addresses with the same value are ordered by their primary key (pk). ... FAIL
======================================================================
FAIL: test_mac_address_ordering_with_duplicates (dcim.tests.test_models.MACAddressTestCase.test_mac_address_ordering_with_duplicates)
Test that MAC addresses with the same value are ordered by their primary key (pk).
----------------------------------------------------------------------
Traceback (most recent call last):
File "/opt/netbox/netbox/dcim/tests/test_models.py", line 82, in test_mac_address_ordering_with_duplicates
self.assertLess(
AssertionError: 12 not less than 1 : MAC addresses with value 12:34:56:78:90:AB are not ordered by primary key
----------------------------------------------------------------------
Ran 1 test in 0.027sand passes with the Test that MAC addresses with the same value are ordered by their primary key (pk). ... ok
----------------------------------------------------------------------
Ran 1 test in 0.028s
OK |
jeremystretch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jseifeddine. I've removed the test as I don't feel it's necessary; there are many other models with a similar pattern for which we don't include an explicit regression test for ordering. With pk added to the model's default ordering this shouldn't be an issue.
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
66e2b3c to
3d2cf79
Compare
Fixes: #19917
Fix MAC address pagination by ensuring deterministic ordering
Add
pkto MACAddress model ordering to ensure deterministic resultswhen 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.