Skip to content
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

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

Closed
ITJamie opened this issue Jan 4, 2023 · 4 comments · Fixed by #12251
Closed

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

ITJamie opened this issue Jan 4, 2023 · 4 comments · Fixed by #12251
Assignees
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application

Comments

@ITJamie
Copy link
Contributor

ITJamie commented Jan 4, 2023

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"

@ITJamie ITJamie added the type: bug A confirmed report of unexpected behavior in the application label Jan 4, 2023
@kkthxbye-code kkthxbye-code added the status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation label Feb 27, 2023
@netbox-community netbox-community deleted a comment from ITJamie Feb 27, 2023
@decoupca
Copy link
Contributor

decoupca commented 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 added a commit to decoupca/netbox that referenced this issue Mar 22, 2023
decoupca added a commit to decoupca/netbox that referenced this issue Mar 22, 2023
@decoupca
Copy link
Contributor

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
Copy link
Contributor

@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
Copy link
Contributor

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

@jeremystretch jeremystretch added status: accepted This issue has been accepted for implementation and removed status: needs owner This issue is tentatively accepted pending a volunteer committed to its implementation labels Apr 20, 2023
jeremystretch pushed a commit that referenced this issue Apr 20, 2023
* Fixes #11383: Sorting search by type doesn't work

* Fixes #11383: Sorting search by type doesn't work; more reliable approach
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: accepted This issue has been accepted for implementation type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants