Laetitia

Laetitia

Why :rpc.call: returns an Inspect.Error?

Hi everybody,

I try to use :rpc.call to create an entity on another node like this:

:rpc.call(:node@me, MyApp, :create_toto, [%{}])

create_toto builds a changeset for Toto Schema and calls Repo.insert.

When the changeset is valid, everything is ok and the result is as expected.

But when the changeset is not valid, i get this error:

{:error,
 %Inspect.Error{
   message: "got UndefinedFunctionError with message \"function Toto.__schema__/1 is undefined (module Toto is not available)\" while inspecting %{__struct__: Ecto.Changeset, action: :insert, changes...... }}

The function works well on its own node.

Can anybody explain this behaviour?

Thanks :wink:

Marked As Solved

voltone

voltone

IEx on the local node is calling inspect on the value returned by :rpc.call/4. So by that time the RPC itself was completed, the exception happens locally in the console.

The RPC worked just fine, and if the call didn’t happen in the console but in some local code, you could process the returned changeset normally. It’s just the rendering in the console that fails in this case. You would have similar problems if you were to try and log the changeset, for example.

You could open a ticket on Ecto to see if the team might consider handling this more gracefully. The question then is what fields should be redacted, because that’s what the custom Inspect protocol is trying to do: hide sensitive data. If the struct is not known locally, how can the changeset inspection decide which fields to show? Should it redact all fields, out of an abundance of caution? Maybe…

Also Liked

voltone

voltone

The calling node is trying to inspect the Ecto.Changeset, which has a custom Inspect protocol implementation that in turn is trying to render the Toto struct that’s embedded inside it. It seems that it does not consider the possibility that the :data field in the changeset is a struct from a module that doesn’t exist locally.

(Edit: it is trying to call __schema__/1 on that module here)

To prevent the error, force the local console to not try and call the Ecto.Changeset inspect implementation, for example by calling IEx.configure(inspect: [structs: false]) before the :rpc call.

Alternatively you could monkey-patch Ecto.Changeset from within iEx:

defimpl Inspect, for: Ecto.Changeset do              
  defdelegate inspect(data, opts), to: Inspect
end

Last Post!

Laetitia

Laetitia

Thank you!!!

The RPC worked just fine, and if the call didn’t happen in the console but in some local code, you could process the returned changeset normally. It’s just the rendering in the console that fails in this case.

It really was this and helped me to find out the real problem. The node that called the remote function was trying to cast the changeset (wich was a changeset error) to a string.

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42533 114
New

We're in Beta

About us Mission Statement