Laetitia

Laetitia

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:

Showing Posts 1 to 10

crova

crova

Does :create_toto resides in MyApp?
I think you should be passing something like MyApp.Toto as the second argument or Toto, idk:
:rpc.call(:node@me, MyApp.Toto || Toto, :create_toto, [%{}]).

The second argument should be the module that defines the function you’ll be calling.

Laetitia

Laetitia OP

Yes, create_toto is a very basic function of the MyApp module like this:

def create_toto(%{} = attrs) do
     Toto.changeset(%Toto{}, %{age: 12}) |> Repo.insert()
end
crova

crova

And Toto is an alias?

Also, could you put all the code involved here? Might be easier seeing everything.

Laetitia

Laetitia OP

Okay, i give a try report it simply:

# my_app.ex
defmodule MyApp do
  alias MyApp.Toto
  alias MyApp.Repo

  def create_toto(%{} = attrs) do
     Toto.changeset(%Toto{}, %{age: 12}) |> Repo.insert()
  end
end

#my_app/toto.ex
defmodule MyApp.Toto do
  use Ecto.Schema

 schema "totos" do
   age: :integer

  timestamps()
 end

def changeset(toto, attrs) do
  too
 |> Ecto.Changeset.cast(attrs, [:age])
 |> Ecto.Changeset.validate_required([:age])
end

end

I am writting this code here for the report. It is not the real code but it allows to understand what is going on.

This app runs on a node A.
The second node try to call like this

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

and on changeset error, get the {:error, %Inspect.Error{}..}

crova

crova

Is the second node the same app as on node A or a different one?

I’m not sure how rpc deals with function calls that invoke functions from other modules. I only ever called functions that don’t rely on other modules.

But from the looks of it, it does not have MyApp.Toto available. Maybe try importing the MyApp.Toto module.

Laetitia

Laetitia OP

I found that if i don’t run :rpc.call from an app, a.k.a, execute directly

~ $ iex --sname lol --cookie MYCOOKIE

i get something like

iex(lol@binary)1> :rpc.call(:my_app@me, MyApp, :create_toto, [%{}])
{:error,
 %{
   __struct__: Ecto.Changeset,
   action: :insert,

So it seems that the :rpc.call caller try to inspect the changeset.

The changeset seems to be inspected with structs: false.

But why and were it is done?

My real problem is that i have problems when i get changeset errors from another node.

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
Laetitia

Laetitia OP

Hi
thank you for the response.
I wonder who is doing the inspect and when it occurs.
And does it means we cannot rely on remote node creation via changeset??

elielhaouzi

elielhaouzi

Does that mean that an ecto.changeset error cannot be passed between nodes ?

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…

Where Next? Top

Trending in Questions Top

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, I’m trying to build a basic Phoenix web-app, and I’d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
mnkhod
So i have been using ash framework for a while and i love it. However currently the issue im having with ash framework is the error handl...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews