Using Ecto.Query in a RemoteExecutionCell

I’ve got Livebook (using the livebook:edge Docker container) set up and properly executing code on a remote node (though I have some configuration questions that I’ll address in a different topic). The only major problem I’m having comes when I try to use Ecto.Query.

If I try to import Ecto.Query, I get an error that says error: module Ecto.Query is not loaded and could not be found.

If I try to use Ecto.Query.from(...) directly without importing it, I get

** (ErlangError) Erlang error: {:exception, :undef, [{Ecto.Query, :from, [Meadow.Data.Schemas.Work, [limit: 1]], []}, {:elixir_eval, :__FILE__, 1, [file: ~c"#cell:gsynocyaqcunidcyirskfy2tyhh2wirn", line: 5]}, {:elixir, :"-eval_external_handler/1-fun-2-", 4, [file: ~c"src/elixir.erl", line: 376]}, {:erl_eval, :do_apply, 7, [file: ~c"erl_eval.erl", line: 750]}, {:erl_eval, :expr_list, 7, [file: ~c"erl_eval.erl", line: 1026]}, {:erl_eval, :expr, 6, [file: ~c"erl_eval.erl", line: 456]}]}
    (kernel 9.0.2) erpc.erl:702: :erpc.call/5
    #cell:gsynocyaqcunidcyirskfy2tyhh2wirn:4: (file)

If I try to require it before using it that way, I get the ...is not loaded and could not be found error again.

Oddly, remote autocomplete finds it just fine:

image

image

Other macros (like Logger.warning/2) seem to work just fine, so it doesn’t seem to be a macro issue.

Can anyone provide any guidance or answers on this?

Hi @mbklein as a basic question, did you Mix.install ecto as a dependency? Can you show the failing livebook?

2 Likes

I didn’t Mix.install Ecto, but since this is a remote execution cell, I figured it would be using the remote node’s Ecto instead of my having to have it installed in the livebook, just like all the other remote node’s dependencies are available to me.

I will try installing it locally as well, in case it’s a macro thing. That would at least explain why Logger works and Ecto doesn’t.

Yup, adding ecto as a dependency of the local notebook got it working.

It’s so easy to lose track of what’s building which AST and passing it off to where in an RPC situation, but it makes sense that macros need to be evaluated before the remote call is made.

1 Like