nautobot / pynautobot

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

Error when printing Virtual-Chassis object #16

Closed jifox closed 2 years ago

jifox commented 3 years ago

there is an error when printing a Virtual Chassis Record

print(record)
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ansible/devel/nautobot-transfer/lib/python3.8/site-packages/pynautobot/models/dcim.py", line 151, in __str__
    return self.master.display_name
AttributeError: 'NoneType' object has no attribute 'display_name'

I could see that the Nautobot API returns the field name instead of display_name

I'll filing a pull request with changes pynautobot/pynautobot/models/dcim.py from

class VirtualChassis(Record):
    def __str__(self):
        return self.master.display_name

to

class VirtualChassis(Record):
    def __str__(self):
        if self.master is None:
            return self.name
        else:
            return self.master.display_name