-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Rack list contains duplicate entries in paginated API responses #3830
Comments
First, this is going to be very difficult to reproduce without any example data. Can you see if you can narrow it down to a specific set of conditions or naming pattern? Second, if this is related to |
Oy! |
So, right now I am now able to reproduce it on a bare new install.
And then, multiple duplicates are returned with |
I'm still searching on my side but I think the bug is now easily reproducible (through the steps described before). |
I can confirm that this is happening when there are racks with the same name. You don't even need to go crazy with the numbers; 50 racks with 10 on the paging limit can recreate this issue. The lower the page limit, the more often you'll see duplicates. I'm also running NetBox directly using
>>> import json, requests
>>>
>>> headers = {'Authorization': 'Token ef1764f45a5dd423e7bb6ba8502aabb9838b0c36', 'Content-type': 'application/json'}
>>>
>>> for i in range(50):
... resp = requests.post('http://netbox/api/dcim/racks/', data='{"name": "rack1", "site": 1}', headers=headers)
...
>>> url = 'http://netbox/api/dcim/racks/?limit=10&brief=true'
>>> results = []
>>>
>>> while url:
... data = json.loads(requests.get(url, headers=headers).content)
... url = data['next']
... results += data['results']
...
>>> for index, result in enumerate(results):
... if results.count(result) > 1:
... print('duplicate', result['id'], 'at', index)
...
duplicate 50 at 9
duplicate 50 at 19
>>> results[9]
{'id': 50, 'url': 'http://netbox/api/dcim/racks/50/', 'name': 'rack1', 'display_name': 'rack1', 'device_count': None}
>>> results[19]
{'id': 50, 'url': 'http://netbox/api/dcim/racks/50/', 'name': 'rack1', 'display_name': 'rack1', 'device_count': None} |
I haven't gone around testing it, but this should be affecting other models too as ordering is not guaranteed if left unspecified as warned about in Django's docs. |
@hSaria Yeah, I think what's happening is that the ordering of Rack objects for which the set |
I've tested the same thing on devices by leaving the name empty and it does also return duplicates. I suppose it's rare that people create into duplicate objects. I'll go through the models to try to figure out which ones can be dup-ed with the current order, but the eyes of someone more experienced would definitely prove worthy. |
FYI the apparent solution here is to simply append |
Found and confirmed (tested) the following:
I'll work on a PR for this. I don't mind if someone else wants to. |
Hold off on the PR for now. This will require introducing new migrations and I'd rather avoid having to refactor the significant number of migrations pending for v2.7. |
Fixes #3830: Update model ordering parameters to ensure deterministic ordering
This will be fixed in the v2.7 release. |
Environment
Steps to Reproduce
Expected Behavior
List all racks without duplicates.
Expected Behavior
Some duplicated racks.
Context
We have around 4500 racks and we have only one duplicate.
Script used to reproduce the isse
And then run
dup.pl | sort | uniq -d
Links
This might be a regression, or at least link to: #2938
The text was updated successfully, but these errors were encountered: