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

Choices returned from OPTIONS have some shown as display and others as displayname #382

Closed
FragmentedPacket opened this issue Apr 27, 2021 · 3 comments · Fixed by #391
Closed
Labels
type: bug Something isn't working as expected
Milestone

Comments

@FragmentedPacket
Copy link
Contributor

Environment

  • Python version: 3.7.9
  • Nautobot version: 1.0.0

Steps to Reproduce

Mainly know how to do this with pynautobot, but it appears we can just make an OPTIONS call to the list endpoint.
https://github.com/nautobot/pynautobot/blob/develop/pynautobot/core/endpoint.py#L309

>>> from pynautobot import api
>>> nb = api("http://localhost:8000", "0123456789abcdef0123456789abcdef01234567")
>>> nb.dcim.racks.choices()
>>> from pprint import pprint
>>> pprint(nb.dcim.racks.choices())
{'outer_unit': [{'display_name': 'Millimeters', 'value': 'mm'},
                {'display_name': 'Inches', 'value': 'in'}],
 'status': [{'display': 'Active', 'value': 'active'},
            {'display': 'Available', 'value': 'available'},
            {'display': 'Connected', 'value': 'connected'},
            {'display': 'Container', 'value': 'container'},
            {'display': 'Decommissioned', 'value': 'decommissioned'},
            {'display': 'Decommissioning', 'value': 'decommissioning'},
            {'display': 'Deprecated', 'value': 'deprecated'},
            {'display': 'Deprovisioning', 'value': 'deprovisioning'},
            {'display': 'DHCP', 'value': 'dhcp'},
            {'display': 'Failed', 'value': 'failed'},
            {'display': 'Inventory', 'value': 'inventory'},
            {'display': 'Offline', 'value': 'offline'},
            {'display': 'Planned', 'value': 'planned'},
            {'display': 'Provisioning', 'value': 'provisioning'},
            {'display': 'Reserved', 'value': 'reserved'},
            {'display': 'Retired', 'value': 'retired'},
            {'display': 'Shipped to Customer', 'value': 'shipped-to-customer'},
            {'display': 'SLAAC', 'value': 'slaac'},
            {'display': 'Staged', 'value': 'staged'},
            {'display': 'Staging', 'value': 'staging'}],
 'type': [{'display_name': '2-post frame', 'value': '2-post-frame'},
          {'display_name': '4-post frame', 'value': '4-post-frame'},
          {'display_name': '4-post cabinet', 'value': '4-post-cabinet'},
          {'display_name': 'Wall-mounted frame', 'value': 'wall-frame'},
          {'display_name': 'Wall-mounted cabinet', 'value': 'wall-cabinet'}],
 'width': [{'display_name': '10 inches', 'value': 10},
           {'display_name': '19 inches', 'value': 19},
           {'display_name': '21 inches', 'value': 21},
           {'display_name': '23 inches', 'value': 23}]}

Expected Behavior

That they all options return {"display": "XXXX", "value": "XXXX}

Observed Behavior

See the steps to reproduce above.

This seems to may have been caused by #321

@FragmentedPacket
Copy link
Contributor Author

FragmentedPacket commented Apr 27, 2021

It seems to most likely only be the status due to it being a model and the change from display_name to display.

@FragmentedPacket
Copy link
Contributor Author

Looking into it, it seems like "a" fix is to revert the return from display back to display_name to align with the other enums that aren't models within https://github.com/nautobot/nautobot/blob/develop/nautobot/core/api/metadata.py.

I'd be willing to implement the fix and add tests for this as well once we get the go forward fix for this issue.

@jathanism jathanism added type: bug Something isn't working as expected status: current labels Apr 28, 2021
@jathanism jathanism added this to the v1.1.0 milestone Apr 28, 2021
@jathanism jathanism added this to To do in Release v1.1.0 via automation Apr 28, 2021
@jathanism
Copy link
Contributor

jathanism commented Apr 28, 2021

Looking into it, it seems like "a" fix is to revert the return from display back to display_name to align with the other enums that aren't models within https://github.com/nautobot/nautobot/blob/develop/nautobot/core/api/metadata.py.

I'd be willing to implement the fix and add tests for this as well once we get the go forward fix for this issue.

We need the inverse in fact. We deliberately changed all display_name values to display, so we'll need to do the same to these fields. This metadata key name is a default from DRF metadata emitter, so we'll likely just need to overload the base method to get it to apply to all field types.

@glennmatthews glennmatthews moved this from To do to Review in progress in Release v1.1.0 Apr 29, 2021
Release v1.1.0 automation moved this from Review in progress to Done Apr 30, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
type: bug Something isn't working as expected
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants