globalsearch: search result view: ordering results by object_type not working #7452

Closed
opened 2025-12-29 20:23:36 +01:00 by adam · 4 comments
Owner

Originally created by @ITJamie on GitHub (Jan 4, 2023).

Originally assigned to: @decoupca on GitHub.

NetBox version

v3.4.2

Python version

3.10

Steps to Reproduce

goto: https://demo.netbox.dev/search/?q=100
press "Type" on the search results table header, results do not re-order

Expected Behavior

objects to be grouped together by object type when sorted by object_type. instead "field" seems to take precidence

Observed Behavior

Some of the same object types are split apart, eg on the demo site some of the device types are separated, also when you try and order in reverse the order does not seem to change.

In our internal instance we sometimes see devices intermingled with other objects.

sorting by "field" works as expected, sorting by "type" does not and seems to fallback to sorting by "field"

Originally created by @ITJamie on GitHub (Jan 4, 2023). Originally assigned to: @decoupca on GitHub. ### NetBox version v3.4.2 ### Python version 3.10 ### Steps to Reproduce goto: https://demo.netbox.dev/search/?q=100 press "Type" on the search results table header, results do not re-order ### Expected Behavior objects to be grouped together by object type when sorted by object_type. instead "field" seems to take precidence ### Observed Behavior Some of the same object types are split apart, eg on the demo site some of the device types are separated, also when you try and order in reverse the order does not seem to change. In our internal instance we sometimes see devices intermingled with other objects. sorting by "field" works as expected, sorting by "type" does not and seems to fallback to sorting by "field"
adam added the type: bugstatus: accepted labels 2025-12-29 20:23:36 +01:00
adam closed this issue 2025-12-29 20:23:36 +01:00
Author
Owner

@decoupca commented on GitHub (Mar 22, 2023):

I have a PR ready for this one.

Edit: however, looks like ordering by object column also doesn't work as expected.

Since the object's name isn't part of the data passed directly to SearchTable, I'm having a hard time setting the right order_by value for that column. The object's name is generated by linkify(), which calls the model's get_absolute_url() method. I've tried a bunch of accessor strings trying to resolve the object's full name, but no dice.

Some that haven't worked:

  • object___meta__verbose_name
  • object__verbose_name
  • object__name

Any thoughts?

@decoupca commented on GitHub (Mar 22, 2023): I have a PR ready for this one. **Edit**: however, looks like ordering by `object` column also doesn't work as expected. Since the `object`'s name isn't part of the data passed directly to `SearchTable`, I'm having a hard time setting the right `order_by` value for that column. The object's name is generated by `linkify()`, which calls the model's `get_absolute_url()` method. I've tried a bunch of accessor strings trying to resolve the `object`'s full name, but no dice. Some that haven't worked: * `object___meta__verbose_name` * `object__verbose_name` * `object__name` Any thoughts?
Author
Owner

@decoupca commented on GitHub (Mar 23, 2023):

Spent some time in the debugger looking through the result object list, but I couldn't find a single accessor that works across all search result object types. Any accessor I pass to order_by only works on a subset of results, i.e., some of the results are ordered alphabetically like you'd expect, but others aren't. And as far as I can tell, there is no way to provide conditional accessors to order_by. Unless I missed a universal property/accessor that renders an object's name across all object types, the only solution I see would be to add such a universal property/accessor to all object types, but that's clearly beyond the scope of this issue.

I have the original issue resolved. @kkthxbye-code do you want me to move forward with that as a PR and leave object sorting as a separate bug, or do you have another idea on how to take care of object sorting too?

@decoupca commented on GitHub (Mar 23, 2023): Spent some time in the debugger looking through the result object list, but I couldn't find a single accessor that works across all search result object types. Any accessor I pass to `order_by` only works on a subset of results, i.e., some of the results are ordered alphabetically like you'd expect, but others aren't. And as far as I can tell, there is no way to provide conditional accessors to `order_by`. Unless I missed a universal property/accessor that renders an object's name across all object types, the only solution I see would be to add such a universal property/accessor to all object types, but that's clearly beyond the scope of this issue. I have the original issue resolved. @kkthxbye-code do you want me to move forward with that as a PR and leave object sorting as a separate bug, or do you have another idea on how to take care of object sorting too?
Author
Owner

@decoupca commented on GitHub (Mar 28, 2023):

@jeremystretch care to weigh in here? I can submit a PR for the original bugfix & open a new issue but wanted maintainer input first.

@decoupca commented on GitHub (Mar 28, 2023): @jeremystretch care to weigh in here? I can submit a PR for the original bugfix & open a new issue but wanted maintainer input first.
Author
Owner

@decoupca commented on GitHub (Apr 14, 2023):

Submitted my PR for original issue, opening new issue for object column sorting

@decoupca commented on GitHub (Apr 14, 2023): Submitted my PR for original issue, opening new issue for object column sorting
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7452