Skip to content

Commit 134df72

Browse files
hugobaraunajonatanklosko
authored andcommitted
Fix saving notebook to S3 file system (#3134)
1 parent 5a4cfdc commit 134df72

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lib/livebook/file_system/s3.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ defmodule Livebook.FileSystem.S3 do
2222
token: String.t() | nil
2323
}
2424

25+
@derive {Inspect, except: [:access_key_id, :secret_access_key]}
26+
2527
embedded_schema do
2628
field :bucket_url, :string
2729
field :external_id, :string

lib/livebook_web/live/session_live/persistence_component.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ defmodule LivebookWeb.SessionLive.PersistenceComponent do
1111
end
1212

1313
@impl true
14+
def update(%{event: {:mount_file_system, file_system}}, socket) do
15+
:ok = FileSystem.mount(file_system)
16+
{:ok, socket}
17+
end
18+
1419
def update(%{event: {:set_file, file, _info}}, socket) do
1520
current_file = socket.assigns.draft_file
1621

test/livebook_web/live/session_live_test.exs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,6 +1612,21 @@ defmodule LivebookWeb.SessionLiveTest do
16121612
refute render(view) =~ new_dir.path
16131613
assert render(view) =~ old_dir.path
16141614
end
1615+
1616+
test "switching to S3 file system in persistence dialog does not crash",
1617+
%{conn: conn, session: session} do
1618+
s3_fs = build(:fs_s3)
1619+
Livebook.HubHelpers.persist_file_system(s3_fs)
1620+
1621+
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}/settings/file")
1622+
1623+
view
1624+
|> element(~s{button[phx-click="set_file_system"][phx-value-id="#{s3_fs.id}"]})
1625+
|> render_click()
1626+
1627+
# The component should handle the mount_file_system event without crashing
1628+
assert render(view) =~ "Save to file"
1629+
end
16151630
end
16161631

16171632
describe "completion" do

0 commit comments

Comments
 (0)