Skip to content

Conversation

@mscolnick
Copy link
Contributor

@mscolnick mscolnick commented Nov 24, 2025

marimo edit /absolute/path/to/dir would fail to open any notebooks. A relative directory like marimo edit path/to/dir would work, but not an absolute directory. This fixes that case.

@vercel
Copy link

vercel bot commented Nov 24, 2025

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

Project Deployment Preview Comments Updated (UTC)
marimo-docs Ready Ready Preview Comment Nov 25, 2025 2:38pm
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 fixes a bug where marimo edit /absolute/path/to/dir would fail to open notebooks. The fix adds path resolution logic to handle both absolute and relative file paths when a router is configured with an absolute directory.

  • Adds a new get_file_manager override in LazyListOfFilesAppFileRouter to resolve relative file paths against the router's directory
  • Implements security checks to prevent accessing files outside the allowed directory
  • Includes comprehensive test coverage for the absolute directory path scenarios

Reviewed changes

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

File Description
tests/_server/test_file_manager_absolute_path.py New comprehensive test file covering absolute directory path scenarios, including security tests for path traversal prevention
marimo/_server/file_router.py Adds get_file_manager method override to LazyListOfFilesAppFileRouter class to handle path resolution for absolute directories

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

files = router.files
assert len(files) > 0
file_info = files[0]
print(f"File path from router.files: {file_info.path}")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Copilot uses AI. Check for mistakes.
# Now simulate the frontend sending just the basename
# (This is what might be happening in the bug)
basename = "notebook.py"
print(f"Attempting to open with basename: {basename}")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Copilot uses AI. Check for mistakes.
file_manager_from_basename = router.get_file_manager(basename)
assert file_manager_from_basename is not None
assert file_manager_from_basename.is_notebook_named
print("SUCCESS: Opened file with basename")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Suggested change
print("SUCCESS: Opened file with basename")
# Successfully opened file with basename
Copilot uses AI. Check for mistakes.
assert file_manager_from_basename.is_notebook_named
print("SUCCESS: Opened file with basename")
except HTTPException as e:
print(f"FAILED: {e.detail}")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Suggested change
print(f"FAILED: {e.detail}")
Copilot uses AI. Check for mistakes.

# Try to open with relative path
relative_path = "subdir/notebook.py"
print(f"Attempting to open with relative path: {relative_path}")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Suggested change
print(f"Attempting to open with relative path: {relative_path}")
Copilot uses AI. Check for mistakes.
file_manager = router.get_file_manager(relative_path)
assert file_manager is not None
assert file_manager.is_notebook_named
print("SUCCESS: Opened file with relative path")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Suggested change
print("SUCCESS: Opened file with relative path")
Copilot uses AI. Check for mistakes.
assert file_manager.is_notebook_named
print("SUCCESS: Opened file with relative path")
except HTTPException as e:
print(f"FAILED: {e.detail}")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Suggested change
print(f"FAILED: {e.detail}")
Copilot uses AI. Check for mistakes.

# All paths should be absolute
for file_info in files:
print(f"File: {file_info.name}, Path: {file_info.path}")
Copy link

Copilot AI Nov 25, 2025

Choose a reason for hiding this comment

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

Debug print statements should not be committed to the codebase. Remove this print statement or replace it with proper logging if this output is needed for debugging purposes.

Suggested change
print(f"File: {file_info.name}, Path: {file_info.path}")
Copilot uses AI. Check for mistakes.
@mscolnick mscolnick merged commit 31f63cc into main Nov 25, 2025
39 of 41 checks passed
@mscolnick mscolnick deleted the ms/fix-absolute-directory branch November 25, 2025 18:13
@mscolnick mscolnick added the bug Something isn't working label Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

2 participants