nautobot / pynautobot

Nautobot Python SDK
https://pynautobot.readthedocs.io/en/latest/index.html
Apache License 2.0
36 stars 32 forks source link

Circuits has no attribute cid #222

Closed TitouanS31 closed 1 month ago

TitouanS31 commented 1 month ago

I found a bug by trying to enumerate the cables in the Nautobot demo. Here is the code to get the bug.

import pynautobot

nautobot = pynautobot.api(
    url="https://demo.nautobot.com",
    token="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
)

for cable in nautobot.dcim.cables.all():
    print(cable)

I was expecting to get a string representation of all the cables but instead, I got the following exception.

Ethernet1/1 <> Ethernet1/1
Traceback (most recent call last):
  File "c:\Users\foo\Documents\misc\circuit_bug.py", line 14, in <module>
    print(cable)
  File "C:\Users\foo\AppData\Roaming\Python\Python310\site-packages\pynautobot\models\dcim.py", line 228, in __str__
    return "{} <> {}".format(self.termination_a, self.termination_b)
  File "C:\Users\foo\AppData\Roaming\Python\Python310\site-packages\pynautobot\models\dcim.py", line 217, in __str__
    return self.circuit.cid
AttributeError: type object 'Circuits' has no attribute 'cid'

I think it is related to the termination type, it seems not to like circuits.

Maybe the __str__ function of the Termination class is a bit too hacky (cf. model/dcim.py).

Nautobot version: 2.2.8 Pynautobot version: 2.2.0