fix: prevent NameError in marimo run when passing mo.md() between cells (#7994)#8692
Open
fix: prevent NameError in marimo run when passing mo.md() between cells (#7994)#8692
NameError in marimo run when passing mo.md() between cells (#7994)#8692Conversation
…en cells (#7994) ## Description `_extract_markdown` in `compiler.py` incorrectly matched assignment statements like `title = mo.md("# Hello World")` as markdown-only cells, because both `ast.Expr` and `ast.Assign` nodes have a `.value` attribute. In `marimo run` mode, `_handle_markdown_cells_on_instantiate` would then skip executing these cells entirely, causing downstream `NameError`s when other cells referenced the assigned variable. The fix adds an `isinstance(body, ast.Expr)` check so only bare `mo.md()` expressions are treated as markdown cells.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where _extract_markdown in compiler.py incorrectly treated assignment statements like title = mo.md("# Hello World") as markdown-only cells. Both ast.Expr and ast.Assign have a .value attribute, so the existing code matched assignments too. In marimo run mode, such cells were skipped rather than executed, causing NameErrors in downstream cells referencing the assigned variable.
Changes:
- Added an
isinstance(body, ast.Expr)guard in_extract_markdownto only match baremo.md()expressions - Added unit tests for various non-markdown
mo.md()usages (assignment, annotated assignment, multi-statement) - Added an integration test and smoke test reproducing the original bug scenario
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
marimo/_ast/compiler.py |
Added isinstance(body, ast.Expr) check to prevent assignments from being treated as markdown cells |
tests/_ast/test_compiler.py |
Added TestExtractMarkdown class with unit tests for the fix |
tests/_ast/test_app.py |
Added integration test verifying mo.md() objects can be passed between cells in run mode |
marimo/_smoke_tests/markdown/cross_cell_md.py |
Added smoke test notebook reproducing the bug scenario |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dmadisetti
approved these changes
Mar 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
_extract_markdownincompiler.pyincorrectly matched assignment statements liketitle = mo.md("# Hello World")as markdown-only cells, because bothast.Exprandast.Assignnodes have a.valueattribute. Inmarimo runmode,_handle_markdown_cells_on_instantiatewould then skip executing these cells entirely, causing downstreamNameErrors when other cells referenced the assigned variable.The fix adds an
isinstance(body, ast.Expr)check so only baremo.md()expressions are treated as markdown cells.