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

[Bug] KeyError: 'warnings' due to sandbox #655

Open
leonard-henriquez opened this issue Sep 29, 2024 · 1 comment
Open

[Bug] KeyError: 'warnings' due to sandbox #655

leonard-henriquez opened this issue Sep 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@leonard-henriquez
Copy link

What are you really trying to do?

Use Sentry with Temporal to track and manage warnings within workflows.

Describe the bug

Sentry’s catch_warnings context manager, which relies on the standard Python warnings module, raises a KeyError in Temporal workflows because the warnings module is not available. This happens in environments managed by Temporal, which restricts access to certain standard Python modules like warnings.

This restriction leads to a failure when using libraries like Sentry that depend on this module for capturing and managing Python warnings.

Error Example:

KeyError: 'warnings'

Cause: The warnings module is not present or accessible within the Temporal workflow environment, causing the code to fail when it tries to reference sys.modules['warnings'].

Minimal Reproduction

To reproduce this issue:

1.	Set up a Temporal workflow in Python.
2.	Integrate Sentry’s catch_warnings context manager or any other library that uses the warnings module.
3.	Trigger a Python warning within the workflow (e.g., by using warnings.warn()).
4.	The workflow fails with a KeyError: 'warnings' due to the restricted access.

Here’s a minimal code snippet:

def workflow_function():
    with warnings.catch_warnings(record=True) as w:
        warnings.warn("This is a test warning")

Environment/Versions

•	OS and processor: MacBook Pro M1
•	Temporal Version: 1.7.1
•	Are you using Docker or Kubernetes?: Using Docker to run Temporal
@leonard-henriquez leonard-henriquez added the bug Something isn't working label Sep 29, 2024
@cretz
Copy link
Member

cretz commented Sep 30, 2024

  1. Integrate Sentry’s catch_warnings context manager or any other library that uses the warnings module.

You're going to have to pass through the imports and disable the sandbox I believe. warnings is not a determinism-safe module (and Sentry likely isn't either). Using non-deterministic modules like Sentry require pass through and sandbox avoidance. https://github.com/temporalio/sdk-python?tab=readme-ov-file#workflow-sandbox explains how the sandbox works and how to disable for parts of code. Similar pass through and avoidance techniques are applied in our Sentry interceptor in the sample at https://github.com/temporalio/samples-python/tree/main/sentry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants