nautobot / pynautobot

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

Fixed issue where circuit details are not known without fetching them #224

Closed tsm1th closed 1 month ago

tsm1th commented 1 month ago

This closes #222.

The other termination type includes the identifier name in the original API call, so it's not an issue. For a circuit termination type, the identifier circuit.cid is not in the original API call. That's why an additional fetch is necessary.

Pynautobot usually handles this with the __getattr__ method. However, this does not work in this case because the Circuit object has not been initialized yet. Once initialized via full_details(), the __getattr__ works as expected.

Another solution was to increase the depth param on the API call, but it added performance overhead that wasn't ideal.

joewesch commented 1 month ago

Can you add a test to cover what this actually fixes?

tsm1th commented 1 month ago

@joewesch - The solution here was much simpler than I realized. The original issue stemmed from trying to rely on data from the termination object's parent to generate a __str__ method. This is not how nautobot does it. The termination object itself has a display attribute that handles this. This is viewable in the api when you look at a dcim.interface, circuits.circuittermination, or other termination object type.

TLDR - There was no reason to generate our own __str__ method using the parent of the termination object.

I updated the test that was checking this (to include the display attribute) and renamed it to more accurately demonstrate what it's doing.