Skip to content

Fix recursion depth error in _redact_exception_with_context#61776

Merged
potiuk merged 2 commits intoapache:mainfrom
potiuk:avoid-recursion-limit-for-exceptions-in-secrets-masker
Feb 12, 2026
Merged

Fix recursion depth error in _redact_exception_with_context#61776
potiuk merged 2 commits intoapache:mainfrom
potiuk:avoid-recursion-limit-for-exceptions-in-secrets-masker

Conversation

@potiuk
Copy link
Member

@potiuk potiuk commented Feb 11, 2026

Fix recursion depth check in _redact_exception_with_context_or_cause. There are some obscure cases where exception might point to itself in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in #61254 - enhanced with the case of removal of too-deep exceptions rather than not-redacting it (and replacing it with sentinel exception explaining that reminder of the stack trace has been removed.


Was generative AI tooling used to co-author this PR?
  • Yes (please specify the tool below)

Generated-by: Copilot + Claude Sonnet 4.5 following the guidelines


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@potiuk potiuk added backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch backport-to-v2-11-test Mark PR with this label to backport to v2-11-test branch labels Feb 11, 2026
@potiuk potiuk force-pushed the avoid-recursion-limit-for-exceptions-in-secrets-masker branch 2 times, most recently from 42caffe to 5326a05 Compare February 11, 2026 14:16
@potiuk potiuk changed the title Add comprehensive tests for _redact_exception_with_context_or_cause Fix recursion depth error in _redact_exception_with_context Feb 11, 2026
Fix recursion depth check in _redact_exception_with_context_or_cause.
There are some obscure cases where exception might point to itself
in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in apache#61254 - enhanced
with the case of removal of too-deep exceptions rather than
not-redacting it (and replacing it with sentinel exception explaining
that reminder of the stack trace has been removed.

Co-authored-by: Anton Nitochkin <nitochkin@google.com>
@potiuk potiuk force-pushed the avoid-recursion-limit-for-exceptions-in-secrets-masker branch from 5326a05 to cc6b24c Compare February 11, 2026 20:28
@jscheffl jscheffl requested a review from Copilot February 11, 2026 21:17
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the SecretsMasker exception redaction logic to safely handle circular __context__/__cause__ chains and to cap traversal using a recursion/visit limit, preventing RecursionError during log masking.

Changes:

  • Replace _redact_exception_with_context with _redact_exception_with_context_or_cause, adding cycle detection and a max-visit limit with a sentinel exception when truncating.
  • Update the log filter to call the new redaction helper.
  • Add extensive unit tests covering context/cause chaining, cycles, branching, and depth-limit behavior.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
shared/secrets_masker/src/airflow_shared/secrets_masker/secrets_masker.py Introduces cycle/limit-aware exception redaction and switches the filter to use it.
shared/secrets_masker/tests/secrets_masker/test_secrets_masker.py Adds new tests for the updated exception redaction behavior across multiple chaining scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@jscheffl jscheffl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to have AI used again. Not too bad as review. But approved anyway.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@potiuk
Copy link
Member Author

potiuk commented Feb 11, 2026

Wanted to have AI used again. Not too bad as review. But approved anyway.

Not bad indeed.

@potiuk
Copy link
Member Author

potiuk commented Feb 11, 2026

Wanted to have AI used again. Not too bad as review. But approved anyway.

Not bad indeed.

But I still see review rather as an opportunity to have human-human interaction.

@jscheffl
Copy link
Contributor

Wanted to have AI used again. Not too bad as review. But approved anyway.

Not bad indeed.

But I still see review rather as an opportunity to have human-human interaction.

100% - I just started it as another pair of eyes :-D

@potiuk potiuk merged commit 1533ecf into apache:main Feb 12, 2026
62 checks passed
@potiuk potiuk deleted the avoid-recursion-limit-for-exceptions-in-secrets-masker branch February 12, 2026 00:18
@github-actions
Copy link

Backport failed to create: v2-11-test. View the failure log Run details

Status Branch Result
v2-11-test Commit Link

You can attempt to backport this manually by running:

cherry_picker 1533ecf v2-11-test

This should apply the commit to the v2-11-test branch and leave the commit in conflict state marking
the files that need manual conflict resolution.

After you have resolved the conflicts, you can continue the backport process by running:

cherry_picker --continue

If you don't have cherry-picker installed, see the installation guide.

github-actions bot pushed a commit that referenced this pull request Feb 12, 2026
…xt (#61776)

* Fix recursion depth error in _redact_exception_with_context

Fix recursion depth check in _redact_exception_with_context_or_cause.
There are some obscure cases where exception might point to itself
in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in #61254 - enhanced
with the case of removal of too-deep exceptions rather than
not-redacting it (and replacing it with sentinel exception explaining
that reminder of the stack trace has been removed.

Co-authored-by: Anton Nitochkin <nitochkin@google.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------
(cherry picked from commit 1533ecf)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: Anton Nitochkin <nitochkin@google.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@github-actions
Copy link

Backport successfully created: v3-1-test

Status Branch Result
v3-1-test PR Link

@potiuk potiuk added this to the Airflow 3.1.8 milestone Feb 12, 2026
github-actions bot pushed a commit to aws-mwaa/upstream-to-airflow that referenced this pull request Feb 12, 2026
…xt (apache#61776)

* Fix recursion depth error in _redact_exception_with_context

Fix recursion depth check in _redact_exception_with_context_or_cause.
There are some obscure cases where exception might point to itself
in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in apache#61254 - enhanced
with the case of removal of too-deep exceptions rather than
not-redacting it (and replacing it with sentinel exception explaining
that reminder of the stack trace has been removed.

Co-authored-by: Anton Nitochkin <nitochkin@google.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------
(cherry picked from commit 1533ecf)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: Anton Nitochkin <nitochkin@google.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
ytoprakc pushed a commit to ytoprakc/airflow that referenced this pull request Feb 12, 2026
…1776)

* Fix recursion depth error in _redact_exception_with_context

Fix recursion depth check in _redact_exception_with_context_or_cause.
There are some obscure cases where exception might point to itself
in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in apache#61254 - enhanced
with the case of removal of too-deep exceptions rather than
not-redacting it (and replacing it with sentinel exception explaining
that reminder of the stack trace has been removed.

Co-authored-by: Anton Nitochkin <nitochkin@google.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Anton Nitochkin <nitochkin@google.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Ratasa143 pushed a commit to Ratasa143/airflow that referenced this pull request Feb 15, 2026
…1776)

* Fix recursion depth error in _redact_exception_with_context

Fix recursion depth check in _redact_exception_with_context_or_cause.
There are some obscure cases where exception might point to itself
in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in apache#61254 - enhanced
with the case of removal of too-deep exceptions rather than
not-redacting it (and replacing it with sentinel exception explaining
that reminder of the stack trace has been removed.

Co-authored-by: Anton Nitochkin <nitochkin@google.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------

Co-authored-by: Anton Nitochkin <nitochkin@google.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
potiuk added a commit that referenced this pull request Feb 15, 2026
…xt (#61776)

* Fix recursion depth error in _redact_exception_with_context

Fix recursion depth check in _redact_exception_with_context_or_cause.
There are some obscure cases where exception might point to itself
in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in #61254 - enhanced
with the case of removal of too-deep exceptions rather than
not-redacting it (and replacing it with sentinel exception explaining
that reminder of the stack trace has been removed.

Co-authored-by: Anton Nitochkin <nitochkin@google.com>

* Apply suggestions from code review

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

---------
(cherry picked from commit 1533ecf)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: Anton Nitochkin <nitochkin@google.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
potiuk added a commit that referenced this pull request Feb 15, 2026
…xt (#61776) (#61795)

* Fix recursion depth error in _redact_exception_with_context

Fix recursion depth check in _redact_exception_with_context_or_cause.
There are some obscure cases where exception might point to itself
in cause/context - this PR protects against it.

Changed name to include cause as well.

Initially implemented as a fix to v2-11-test in #61254 - enhanced
with the case of removal of too-deep exceptions rather than
not-redacting it (and replacing it with sentinel exception explaining
that reminder of the stack trace has been removed.



* Apply suggestions from code review



---------
(cherry picked from commit 1533ecf)

Co-authored-by: Jarek Potiuk <jarek@potiuk.com>
Co-authored-by: Anton Nitochkin <nitochkin@google.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-to-v2-11-test Mark PR with this label to backport to v2-11-test branch backport-to-v3-1-test Mark PR with this label to backport to v3-1-test branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments