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

Unable to Sort By Endpoint #113

Closed
nniehoff opened this issue Jul 19, 2023 · 4 comments · Fixed by #116
Closed

Unable to Sort By Endpoint #113

nniehoff opened this issue Jul 19, 2023 · 4 comments · Fixed by #116

Comments

@nniehoff
Copy link
Contributor

nniehoff commented Jul 19, 2023

Environment

  • Python version: 3.10
  • Nautobot version: 1.5.23
  • nautobot-bgp-models version: 0.7.1

Trying to sort peerings list view by endpoint fails. In the demo see https://demo.nautobot.com/plugins/bgp/peerings/?sort=endpoint_a

Expected Behavior

Sorted List View

Observed Behavior

Screenshot 2023-07-18 at 7 16 44 PM
2023-07-19 01:10:30,166 ERROR Internal Server Error: /plugins/bgp/peerings/ - django.request - log - /usr/local/lib/python3.10/site-packages/django/utils/log.py:224
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/nautobot/utilities/views.py", line 116, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/nautobot/core/views/generic.py", line 317, in get
    table = self.table(self.queryset, user=request.user, order_by=order_by)
  File "/usr/local/lib/python3.10/site-packages/nautobot/utilities/tables.py", line 71, in __init__
    super().__init__(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/django_tables2/tables.py", line 365, in __init__
    self.order_by = order_by
  File "/usr/local/lib/python3.10/site-packages/django_tables2/tables.py", line 543, in order_by
    self.data.order_by(self._order_by)
  File "/usr/local/lib/python3.10/site-packages/django_tables2/data.py", line 226, in order_by
    self.data = self.data.order_by(*order_by_accessors)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/query.py", line 1149, in order_by
    obj.query.add_ordering(*field_names)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 2016, in add_ordering
    self.names_to_path(item.split(LOOKUP_SEP), self.model._meta)
  File "/usr/local/lib/python3.10/site-packages/django/db/models/sql/query.py", line 1562, in names_to_path
    raise FieldError("Cannot resolve keyword '%s' into field. "
django.core.exceptions.FieldError: Cannot resolve keyword 'endpoint_a' into field. Choices are: _custom_field_data, created, destination_for_associations, endpoints, id, last_updated, source_for_associ
ations, status, status_id
[pid: 23|app: 0|req: 20339/78527] 10.11.7.227 () {72 vars in 1549 bytes} [Wed Jul 19 01:10:30 2023] GET /plugins/bgp/peerings/?sort=endpoint_a => generated 2039 bytes in 1572 msecs (HTTP/1.1 500) 6 hea
ders in 208 bytes (1 switches on core 1)

Steps to Reproduce

  1. Go to routing --> peerings, sort by Endpoint
@mzbroch
Copy link
Contributor

mzbroch commented Jul 24, 2023

Endpoints are in-memory properties and sorting them would require computing them for every peer instance.

Can I understand Your use case? What could sound like a solution would be to sort based on the Device Name (Routing Instance), or filter based on explicitly declared IPs on the endpoint ?

@mzbroch
Copy link
Contributor

mzbroch commented Jul 24, 2023

Short-term: Error prevented via #116

Long term solution thread : #115

@nniehoff
Copy link
Contributor Author

My use case is simple I have a bunch of endpoints there is a list view in Nautobot I want to sort them to make it easier to grok as a human.

@mzbroch
Copy link
Contributor

mzbroch commented Jul 24, 2023

My use case is simple I have a bunch of endpoints there is a list view in Nautobot I want to sort them to make it easier to grok as a human.

I believe this should be solved by filtering Peering objects and limiting number of results in the table, and not by sorting them - In Your case, You are still looking for specific Peer Endpoint IP Address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants