Weird behavior in custom script #16449
-
I have a script that will poll various support APIs based on manufacturer for warranty information. I have a few variables for the script to help target devices by whatever. Below is the section of my code that compensates for when a script variable isn't filled in: if data['region'] is None:
data['region'] = [x.id for x in Region.objects.all()]
else:
data['region'] = list(Region.objects.get(name=data['region']).id)
if data['site'] is None:
data['site'] = [x.id for x in Site.objects.all()]
else:
data['site'] = list(Site.objects.get(name=data['site']).id)
if data['devicerole'] is None:
data['devicerole'] = [x.id for x in DeviceRole.objects.all()]
else:
data['devicerole'] = list(DeviceRole.objects.get(name=data['devicerole']).id)
if data['manufacturer'] is None:
data['manufacturer'] = [x.id for x in Manufacturer.objects.all()]
else:
data['manufacturer'] = list(Manufacturer.objects.get(name=data['manufacturer']).id)
## End Default Values
devices = [device for device in Device.objects.all() if device.site.region.id in data['region'] and device.site.id in data['site'] and device.role.id in data['devicerole'] and device.device_type.manufacturer.id in data['manufacturer']] This is my 4th iteration trying to get this to work. Currently the error I'm getting in Netbox when running this script with a variable present (in this case the region) is:
I'm not sure I understand why. I'm not iterating over an int. I'm tried just doing And the reason why I have to turn it into a list is because of my nice big list comprehension for |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
As it turns out, this is just python behavior I wasn't aware of. list(1) --> Exception |
Beta Was this translation helpful? Give feedback.
As it turns out, this is just python behavior I wasn't aware of.
list(1) --> Exception
[1] --> All Good