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

Where Next?

Popular in Questions Top

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
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
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
hpopp
To simplify some tasks at work, I wrote and published this package yesterday. It’s a simple macro that enables Access behaviour on struct...
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
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New

Other popular topics Top

peerreynders
Manning 2016 Halloween weekend sale via Deal of the Day Friday, October 28 - Half off all MEAPs - code WM102816LT Saturday, October 29 ...
326 29600 154
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
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

We're in Beta

About us Mission Statement