Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stray StopIteration from DatapointsSubscriptionAPI.iterate_data #2013

Open
henrikhestnes opened this issue Nov 8, 2024 · 2 comments
Open
Assignees
Labels

Comments

@henrikhestnes
Copy link

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

@henrikhestnes henrikhestnes changed the title Stray StopIteration from DatapointsSubscriptionAPI.iterate_data Stray StopIteration from DatapointsSubscriptionAPI.iterate_data Nov 8, 2024
@haakonvt
Copy link
Contributor

haakonvt commented Nov 8, 2024

@doctrino could you take a look?

@doctrino doctrino self-assigned this Dec 1, 2024
@doctrino
Copy link
Contributor

doctrino commented Dec 1, 2024

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants