Skip to content

fix: clear warning registry before cell execution to prevent suppressed warnings#9066

Draft
mscolnick wants to merge 2 commits intomainfrom
ms/fix/4821
Draft

fix: clear warning registry before cell execution to prevent suppressed warnings#9066
mscolnick wants to merge 2 commits intomainfrom
ms/fix/4821

Conversation

@mscolnick
Copy link
Copy Markdown
Contributor

Python's default warning filter records shown warnings in __warningregistry__ (stored in the caller's globals dict) and suppresses duplicates. Because marimo re-executes cells in the same globals dict, the registry accumulated entries and caused warnings to disappear on subsequent cell runs.

Clear __warningregistry__ before each cell execution in DefaultExecutor.

Closes #4821

…ed warnings

Python's default warning filter records shown warnings in
`__warningregistry__` (stored in the caller's globals dict) and suppresses
duplicates. Because marimo re-executes cells in the same globals dict, the
registry accumulated entries and caused warnings to disappear on subsequent
cell runs.

Clear `__warningregistry__` before each cell execution in `DefaultExecutor`.

Closes #4821
@mscolnick mscolnick requested a review from dmadisetti as a code owner April 6, 2026 16:52
Copilot AI review requested due to automatic review settings April 6, 2026 16:52
@vercel
Copy link
Copy Markdown

vercel bot commented Apr 6, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
marimo-docs Ready Ready Preview, Comment Apr 6, 2026 7:59pm

Request Review

Copy link
Copy Markdown
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

Fixes a regression where Python warnings could disappear on subsequent marimo cell executions due to accumulation of __warningregistry__ in the shared globals dict.

Changes:

  • Clear __warningregistry__ from the execution globals before each cell execution (sync + async) in DefaultExecutor.
  • Add a regression test asserting the warning registry is cleared on cell re-execution (issue #4821).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
marimo/_runtime/executor.py Clears __warningregistry__ before executing a cell to prevent duplicate-warning suppression across reruns.
tests/_runtime/runner/test_cell_runner.py Adds a regression test validating the warning registry is cleared between reruns.

Comment thread tests/_runtime/runner/test_cell_runner.py Outdated
@mscolnick mscolnick added the bug Something isn't working label Apr 6, 2026
@mscolnick mscolnick enabled auto-merge (squash) April 6, 2026 19:54

class DefaultExecutor(Executor):
@staticmethod
def _clear_warning_registry(glbls: dict[str, Any]) -> None:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here's how scikit deals with this: https://github.com/scikit-image/scikit-image/blob/02bcec701de4c5a9b14497274d6d3e707b1fb861/src/skimage/_shared/_warnings.py#L18

This might be fine, but seems pretty python internal. Doing a bit more reading before signing off

glbls: dict[str, Any],
graph: Optional[DirectedGraph] = None,
) -> Any:
self._clear_warning_registry(glbls)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this might be better as a post hook and not on every cell run. I can't even get the flakiness to occur as is: https://marimo.app/l/decb8n

@mscolnick mscolnick marked this pull request as draft April 8, 2026 02:09
auto-merge was automatically disabled April 8, 2026 02:09

Pull request was converted to draft

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

Successfully merging this pull request may close these issues.

Warnings disappear after subsequent cell run

3 participants