Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: safer check before removing session #3838

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion marimo/_ast/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import ast
import base64
import inspect
import sys
import threading
from dataclasses import asdict, dataclass, field
from pathlib import Path
Expand All @@ -25,7 +26,10 @@
)
from uuid import uuid4

from typing_extensions import ParamSpec, TypeAlias
if sys.version_info < (3, 10):
from typing_extensions import ParamSpec, TypeAlias
else:
from typing import ParamSpec, TypeAlias

from marimo import _loggers
from marimo._ast.cell import Cell, CellConfig, CellId_t, CellImpl
Expand Down
6 changes: 5 additions & 1 deletion marimo/_ast/cell_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os
import random
import string
import sys
from typing import (
TYPE_CHECKING,
Callable,
Expand All @@ -13,7 +14,10 @@
TypeVar,
)

from typing_extensions import ParamSpec, TypeAlias
if sys.version_info < (3, 10):
from typing_extensions import ParamSpec, TypeAlias
else:
from typing import ParamSpec, TypeAlias

from marimo._ast.cell import Cell, CellConfig, CellId_t
from marimo._ast.compiler import cell_factory, toplevel_cell_factory
Expand Down
5 changes: 3 additions & 2 deletions marimo/_server/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,7 +1035,7 @@ def maybe_resume_session(
# Set new session and remove old session
self.sessions[new_session_id] = session
# If the ID is the same, we don't need to delete the old session
if new_session_id != session_id:
if new_session_id != session_id and session_id in self.sessions:
del self.sessions[session_id]
return session

Expand Down Expand Up @@ -1088,7 +1088,8 @@ def close_session(self, session_id: SessionId) -> bool:
)

session.close()
del self.sessions[session_id]
if session_id in self.sessions:
del self.sessions[session_id]
return True

def close_all_sessions(self) -> None:
Expand Down
1 change: 1 addition & 0 deletions tests/snapshots/api.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ hstack
icon
iframe
image
import_guard
islands
MarimoIslandGenerator
MarimoIslandStub
Expand Down
Loading