Skip to content

Commit 53bc9b8

Browse files
fix: propagate delete in watch mode (#6629)
## 📝 Summary Closes #6628 Previously the `--watch` code path only reported cell changes, not deletions. This PR modifies "changed cells" to include deleted cells such that they can be appropriately cleaned up on reload. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 443c402 commit 53bc9b8

File tree

3 files changed

+182
-73
lines changed

3 files changed

+182
-73
lines changed

marimo/_server/file_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ def reload(self) -> set[CellId_t]:
6666

6767
# Return the changes cell IDs
6868
prev_cell_ids = set(prev_cell_manager.cell_ids())
69-
changed_cell_ids: set[CellId_t] = set()
70-
for cell_id in self.app.cell_manager.cell_ids():
69+
current_cell_ids = set(self.app.cell_manager.cell_ids())
70+
# Capture deleted cells
71+
changed_cell_ids: set[CellId_t] = prev_cell_ids - current_cell_ids
72+
for cell_id in current_cell_ids:
7173
if cell_id not in prev_cell_ids:
7274
changed_cell_ids.add(cell_id)
7375
new_code = self.app.cell_manager.get_cell_code(cell_id)

marimo/_server/sessions.py

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
from marimo._runtime.requests import (
5151
AppMetadata,
5252
CreationRequest,
53+
DeleteCellRequest,
5354
ExecuteMultipleRequest,
5455
ExecutionRequest,
5556
HTTPRequest,
@@ -1205,24 +1206,36 @@ def _handle_file_change(
12051206

12061207
# Auto-run cells if configured
12071208
if should_autorun:
1208-
changed_cell_ids_list = list(changed_cell_ids)
12091209
cell_ids_to_idx = {
12101210
cell_id: idx for idx, cell_id in enumerate(cell_ids)
12111211
}
1212+
deleted = {
1213+
cell_id
1214+
for cell_id in changed_cell_ids
1215+
if cell_id not in cell_ids_to_idx
1216+
}
1217+
changed_cell_ids_list = list(changed_cell_ids - deleted)
12121218
changed_codes = [
12131219
codes[cell_ids_to_idx[cell_id]]
12141220
for cell_id in changed_cell_ids_list
1221+
if cell_id not in deleted
12151222
]
12161223

1217-
# This runs the request and also runs UpdateCellCodes
1218-
session.put_control_request(
1219-
ExecuteMultipleRequest(
1220-
cell_ids=changed_cell_ids_list,
1221-
codes=changed_codes,
1222-
request=None,
1223-
),
1224-
from_consumer_id=None,
1225-
)
1224+
if changed_cell_ids_list:
1225+
# This runs the request and also runs UpdateCellCodes
1226+
session.put_control_request(
1227+
ExecuteMultipleRequest(
1228+
cell_ids=changed_cell_ids_list,
1229+
codes=changed_codes,
1230+
request=None,
1231+
),
1232+
from_consumer_id=None,
1233+
)
1234+
for to_delete in deleted:
1235+
session.put_control_request(
1236+
DeleteCellRequest(cell_id=to_delete),
1237+
from_consumer_id=None,
1238+
)
12261239
else:
12271240
session.write_operation(
12281241
UpdateCellCodes(

0 commit comments

Comments
 (0)