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

Improper list format #65

Closed
JL95741 opened this issue Jun 29, 2022 · 7 comments
Closed

Improper list format #65

JL95741 opened this issue Jun 29, 2022 · 7 comments
Labels
hacktoberfest Good issue for Hactoberfest question Further information is requested

Comments

@JL95741
Copy link

JL95741 commented Jun 29, 2022

Environment

  • Python version: v3.7
  • Nautobot version: v1.3.3

Steps to Reproduce

data_list contains details on the device via webhook including hostname.

  1. in Python:
    nautobot = self.nautobot_obj
    device_hostname = data_list.get('nethostname')
    devices = nautobot.dcim.devices
    device_obj = devices.filter(name=device_hostname)
    interface_list = interfaces.filter(device=device_hostname)

2.run the following in python:
print(type(interface_list))
print(interface_list)

Expected Behavior

<class 'list'>
['Ethernet1/1', 'Ethernet1/2']

Observed Behavior

<class 'list'>
[Ethernet1/1, Ethernet1/2]

@glennmatthews
Copy link
Contributor

Hi, thanks for the report. I'm not entirely certain I understand the described issue though. What are self.nautobot_obj and data_list? Are you using pynautobot or some other API client?

@jvanderaa
Copy link
Contributor

This does look like pynautobot. And the list is a list of objects. There is a string representation of these.

@bryanculver bryanculver transferred this issue from nautobot/nautobot Jul 5, 2022
@jvanderaa
Copy link
Contributor

@JL95741 does this make sense?

@lampwins
Copy link
Member

lampwins commented Jul 5, 2022

@JL95741 this is normal, expected behavior. Your interface_list is a collection of pynautobot.models.dcim.Interfaces instances, not strings. I think the confusion, in this case, is that the __repr__ of a Record in pynautobot is str(self) and __str__ of Interfaces is the display attribute in the API, which is just the name of the interface.

So while it looks like print(interface_list) is supposed to be printing a list of strings, it is, in fact printing a list of object representations.

If you wanted to get the list of names as strings, you could do something like this:

interface_names = [i.name for i in interfaces.filter(device=device_hostname)]

@nautobot/pynautobot, perhaps we can take this as feedback to change the Record __repr__ to include the class name?

@jvanderaa
Copy link
Contributor

Makes sense to make the change in fact. I'll add that to the next milestone. Would that be a breaking change? I don't think it would @lampwins

@lampwins
Copy link
Member

lampwins commented Jul 6, 2022

I would not consider modification of a __repr__ to be a breaking change.

@jvanderaa jvanderaa added the question Further information is requested label Jul 13, 2022
@jvanderaa jvanderaa added the hacktoberfest Good issue for Hactoberfest label Sep 26, 2022
@jvanderaa
Copy link
Contributor

Closing for #67

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hacktoberfest Good issue for Hactoberfest question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants