From a0cc26fd47f8ad2316ce92106eedde813537910e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonatan=20K=C5=82osko?= Date: Fri, 27 Oct 2023 21:35:41 +0200 Subject: [PATCH] Clear cell outputs when moving to bin (#2312) --- lib/livebook/session/data.ex | 2 +- test/livebook/session/data_test.exs | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/livebook/session/data.ex b/lib/livebook/session/data.ex index cb63be8bc..8e938c8a1 100644 --- a/lib/livebook/session/data.ex +++ b/lib/livebook/session/data.ex @@ -1109,7 +1109,7 @@ defmodule Livebook.Session.Data do notebook: Notebook.delete_cell(data.notebook, cell.id), bin_entries: [ %{ - cell: cell, + cell: Map.replace(cell, :outputs, []), section_id: section.id, section_name: section.name, index: Enum.find_index(section.cells, &(&1 == cell)), diff --git a/test/livebook/session/data_test.exs b/test/livebook/session/data_test.exs index 93abbb899..f443967aa 100644 --- a/test/livebook/session/data_test.exs +++ b/test/livebook/session/data_test.exs @@ -780,6 +780,21 @@ defmodule Livebook.Session.DataTest do refute Map.has_key?(cell_infos, "c1") end + test "does not include cell outputs in deleted cells" do + data = + data_after_operations!([ + {:insert_section, @cid, 0, "s1"}, + {:insert_cell, @cid, "s1", 0, :code, "c1", %{}}, + {:set_runtime, @cid, connected_noop_runtime()}, + evaluate_cells_operations(["setup", "c1"]) + ]) + + operation = {:delete_cell, @cid, "c1"} + + assert {:ok, %{bin_entries: [%{cell: %{id: "c1", outputs: []}}]}, _actions} = + Data.apply_operation(data, operation) + end + test "unqueues the cell if it's queued for evaluation" do data = data_after_operations!([