Skip to content

Commit c6aef4f

Browse files
committed
comments
1 parent e8ff613 commit c6aef4f

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

python_modules/dagster/dagster/_core/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,9 @@ def user_code_error_boundary(
280280
"""
281281
check.callable_param(msg_fn, "msg_fn")
282282
check.class_param(error_cls, "error_cls", superclass=DagsterUserCodeExecutionError)
283-
from dagster._utils.error import log_and_redact_stacktrace_if_enabled
283+
from dagster._utils.error import redact_user_stacktrace_if_enabled
284284

285-
with log_and_redact_stacktrace_if_enabled(), raise_execution_interrupts():
285+
with redact_user_stacktrace_if_enabled(), raise_execution_interrupts():
286286
if log_manager:
287287
log_manager.begin_python_log_capture()
288288
try:

python_modules/dagster/dagster/_core/execution/plan/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,13 @@ def op_execution_error_boundary(
4242
as respecting the RetryPolicy if present.
4343
"""
4444
from dagster._core.execution.context.system import StepExecutionContext
45-
from dagster._utils.error import log_and_redact_stacktrace_if_enabled
45+
from dagster._utils.error import redact_user_stacktrace_if_enabled
4646

4747
check.callable_param(msg_fn, "msg_fn")
4848
check.class_param(error_cls, "error_cls", superclass=DagsterUserCodeExecutionError)
4949
check.inst_param(step_context, "step_context", StepExecutionContext)
5050

51-
with log_and_redact_stacktrace_if_enabled(), raise_execution_interrupts():
51+
with redact_user_stacktrace_if_enabled(), raise_execution_interrupts():
5252
step_context.log.begin_python_log_capture()
5353
retry_policy = step_context.op_retry_policy
5454

python_modules/dagster/dagster/_utils/error.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ def _should_redact_user_code_error() -> bool:
103103

104104

105105
@contextlib.contextmanager
106-
def log_and_redact_stacktrace_if_enabled():
106+
def redact_user_stacktrace_if_enabled():
107+
"""Context manager which, if a user has enabled redacting user code errors, logs exceptions raised from within,
108+
and clears the stacktrace from the exception. It also marks the exception to be redacted if it was to be persisted
109+
or otherwise serialized to be sent to Dagster Plus. This is useful for preventing sensitive information from
110+
being leaked in error messages.
111+
"""
107112
if not _should_redact_user_code_error():
108113
yield
109114
else:
@@ -118,6 +123,8 @@ def log_and_redact_stacktrace_if_enabled():
118123

119124
if not existing_error_id:
120125
error_id = str(uuid.uuid4())
126+
127+
# Track the error ID for this exception so we can redact it later
121128
error_id_by_exception.set({**error_id_by_exception.get(), id(e): error_id})
122129
masked_logger = logging.getLogger(_REDACTED_ERROR_LOGGER_NAME)
123130

@@ -126,6 +133,7 @@ def log_and_redact_stacktrace_if_enabled():
126133
exc_info=exc_info,
127134
)
128135

136+
# Redact the stacktrace to ensure it will not be passed to Dagster Plus
129137
raise e.with_traceback(None) from None
130138

131139

python_modules/dagster/dagster_tests/core_tests/test_mask_user_code_errors.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def hunter2():
9999

100100
hunter2()
101101
except Exception as e:
102+
# Mimics behavior of resource teardown, which runs in a
103+
# user_code_error_boundary after the user code raises an error
102104
with user_code_error_boundary(
103105
error_cls=DagsterUserCodeExecutionError,
104106
msg_fn=lambda: "teardown after we raised hunter2 error",

0 commit comments

Comments
 (0)