pynetbox icon indicating copy to clipboard operation
pynetbox copied to clipboard

Iterating over devices works only once

Open sol1james opened this issue 3 years ago • 2 comments

If I iterate over all devices as shown in the example code in the documentation it works only once. Ie if I write code like this:

>>> devices = nb.dcim.devices.all()
>>> for device in devices:
...     print(device.name)
>>> for device in devices:
...     print(device.name)

The print statement in the second for loop doesn't get executed. If I do another call to all() then I get another iterator but this introduces a noticable pause. You used to be able to do this without any pauses.

Is this working as designed?

sol1james avatar Feb 16 '22 06:02 sol1james

Yep, see https://github.com/netbox-community/pynetbox/issues/374.

zachmoody avatar Feb 16 '22 06:02 zachmoody

Thanks for that. I created a pull request to update the documentation to reflect this.

sol1james avatar Feb 18 '22 05:02 sol1james

fixed and merged in #525

abhi1693 avatar Aug 29 '23 04:08 abhi1693