acalejos / merquery

Interactive HTTP Client for Livebook w/ power-ups
MIT License
215 stars 4 forks source link

Unable to save a notebook with a Merquery smart cell to file #13

Closed sylvesterroos closed 4 months ago

sylvesterroos commented 4 months ago

Whenever I add a a Merquery smart cell to my notebook and I try to save it, the session crashes with the following error:

** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for #Reference<26552.1535495339.899285000.201416> of type Reference, Jason.Encoder protocol must always be explicitly implemented. This protocol is implemented for the following type(s): Any, Atom, BitString, Date, DateTime, Decimal, Ecto.Association.NotLoaded, Ecto.Schema.Metadata, Float, Integer, Jason.Fragment, Jason.OrderedObject, List, Map, NaiveDateTime, Time
    (jason 1.4.1) lib/jason.ex:164: Jason.encode!/2
    (livebook 0.12.1) lib/livebook/live_markdown/export.ex:230: Livebook.LiveMarkdown.Export.render_cell/2
    (livebook 0.12.1) lib/livebook/live_markdown/export.ex:173: anonymous fn/3 in Livebook.LiveMarkdown.Export.render_section/3
    (elixir 1.16.3) lib/enum.ex:1826: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (elixir 1.16.3) lib/enum.ex:1826: Enum."-map_reduce/3-lists^mapfoldl/2-0-"/3
    (livebook 0.12.1) lib/livebook/live_markdown/export.ex:165: Livebook.LiveMarkdown.Export.render_section/3
    (elixir 1.16.3) lib/enum.ex:1700: Enum."-map/2-lists^map/1-1-"/2
    (livebook 0.12.1) lib/livebook/live_markdown/export.ex:91: Livebook.LiveMarkdown.Export.render_notebook/2
Function: #Function<49.76010102/0 in Livebook.Session.maybe_save_notebook_async/1>
    Args: []

Replication:

  1. Create a new notebook
  2. Install Merquery ({:merquery, github: "acalejos/merquery"}), click reconnect and setup
  3. Save the file to disk
  4. Add a Merquery smart cell
  5. Execute any request, e.g. a GET to https://v2.jokeapi.dev/joke/Any
  6. Manually save the file to disk using the save button on the bottom right, click "Save"

I'm using Livebook 0.12.1

acalejos commented 4 months ago

Can you look at the 'attrs' for the cell that's breaking?

Try copying them and Jason decode followed by a Base.decode64(padding: false)

This was a behavior with an older version that used an ETS table to store bindings and would hold the reference in attrs, which is why it wouldn't serialize. But this shouldn't be the behavior for the current version on main

sylvesterroos commented 4 months ago

Where do I find the attrs?

acalejos commented 4 months ago

If you click to export at the top right does it break? If not, you can find the attrs as a comment above the smart cell in the markdown. It might not work considering that it's the serialization that is breaking

sylvesterroos commented 4 months ago

Yup, export causes a crash

sylvesterroos commented 4 months ago

Firstly, I was using a cached version of the Merquery dependency. However, avoiding the cache using the force: true flag on Mix.install doesn't work because mix.exs expects the curl_req dependency to be located in your Documents folder

acalejos commented 4 months ago

Ok can you try adding 'force: true' as the last argument in your Mix.install?

It might be working on a cached version instead of main

acalejos commented 4 months ago

Ok yeah that's a mistake from late night coding. I had to fork curl req. lemme try updating it.

acalejos commented 4 months ago

Ok try repulling with force true

sylvesterroos commented 4 months ago

It's working now :smile:

acalejos commented 4 months ago

Awesome! Sorry about that lol. Also there's a new download and import from file feature you should have now. Try it out and let me know what you think

sylvesterroos commented 4 months ago

Not sure if you wanted to continue the convo in this issue, but the download and the importing of the download works without issues as far as I can tell :)