fix: clear warning registry before cell execution to prevent suppressed warnings#9066
fix: clear warning registry before cell execution to prevent suppressed warnings#9066
Conversation
…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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
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) inDefaultExecutor. - 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. |
|
|
||
| class DefaultExecutor(Executor): | ||
| @staticmethod | ||
| def _clear_warning_registry(glbls: dict[str, Any]) -> None: |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
Pull request was converted to draft
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 inDefaultExecutor.Closes #4821