Stray `StopIteration` from `DatapointsSubscriptionAPI.iterate_data`
System information (please complete the following information):
- OS: Debian GNU/Linux 12 (bookworm)
- Python Version: 3.12.7
- SDK Version: 7.64.7
Error occurred around 2024-11-07 19:07:02 UTC
Describe the bug
In the SDK, specifically within the DatapointsSubscriptionAPI.iterate_data method, there appears to be an unhandled StopIteration exception. This exception is likely triggered by an unprotected next(iterator) call, where the iterator is exhausted without providing a default value or proper handling of the StopIteration exception. As a result, Python raises a RuntimeError when the exception propagates to the generator function. Unfortunately, I do not have the complete stack trace at this time, but I have implemented logging to capture it if the issue reoccurs.
To Reproduce Run this for long enough
from cognite.client import CogniteClient
client = CogniteClient()
for batch in client.time_series.subscriptions.iterate_data("my_subscription"):
# Do work. Will at some point get excepted by a `RuntimeError: generator raised StopIteration`
Expected behavior
StopIteration to be caught and properly handled by the SDK instead of propagating to the user.
Additional context Dataset ID and Subscription External ID can be provided upon request
@doctrino could you take a look?
@henrikhestnes I have looked into this one, and I cannot recreate the behavior your are observing. Furthermore, looking at the code this is an infinite loop (while True) that continues to check for updates to the subscriptions until you break out of it. I don't think there is an execution path that can lead to a StopIteration.
Can you provide more details so I can recreate it? Or a full traceback?