Shenrak
Hi everyone,
I am trying to use Ecto.insert, and i have the following error :
[error] #PID<0.416.0> running GORprojectWeb.Endpoint (cowboy_protocol) terminated
Server: localhost:4000 (http)
Request: POST /api/rooms
** (exit) an exception was raised:
** (FunctionClauseError) no function clause matching in GORprojectWeb.ErrorHelpers.translate_error/1
(gor_project) lib/gor_project_web/views/error_helpers.ex:9: GORprojectWeb.ErrorHelpers.translate_error("is invalid")
(ecto) lib/ecto/changeset.ex:2345: anonymous fn/3 in Ecto.Changeset.merge_error_keys/3
(elixir) lib/enum.ex:1925: Enum."-reduce/3-lists^foldl/2-0-"/3
(ecto) lib/ecto/changeset.ex:2339: Ecto.Changeset.traverse_errors/2
(gor_project) lib/gor_project_web/views/changeset_view.ex:17: GORprojectWeb.ChangesetView.render/2
(phoenix) lib/phoenix/view.ex:332: Phoenix.View.render_to_iodata/3
(phoenix) lib/phoenix/controller.ex:740: Phoenix.Controller.do_render/4
(gor_project) lib/gor_project_web/controllers/room_controller.ex:1: GORprojectWeb.RoomController.action/2
(gor_project) lib/gor_project_web/controllers/room_controller.ex:1: GORprojectWeb.RoomController.phoenix_controller_pipeline/2
(gor_project) lib/gor_project_web/endpoint.ex:1: GORprojectWeb.Endpoint.instrument/4
(phoenix) lib/phoenix/router.ex:278: Phoenix.Router.__call__/1
(gor_project) lib/gor_project_web/endpoint.ex:1: GORprojectWeb.Endpoint.plug_builder_call/2
(gor_project) lib/gor_project_web/endpoint.ex:1: GORprojectWeb.Endpoint.call/2
(plug) lib/plug/adapters/cowboy/handler.ex:16: Plug.Adapters.Cowboy.Handler.upgrade/4
(cowboy) /Users/giom/Documents/develop/web/GORProject-API/deps/cowboy/src/cowboy_protocol.erl:442: :cowboy_protocol.execute/4
After some investigations, it seems that the error comes from an association not loaded, but the errors kind of triggers me because i have in my errors.pot the strings to handle this error :
## From Ecto.Changeset.put_change/3
msgid "is invalid"
msgstr ""
So i should be handled.
Here are my schemas, CRUD and controller :
Schema :
defmodule GORproject.Rooms.Room do
use Ecto.Schema
import Ecto.Changeset
alias GORproject.Rooms.Room
alias GORproject.Auth.User
schema "rooms" do
field(:depth, :integer)
field(:name, :string)
field(:description, :string)
field(:public, :boolean)
many_to_many(:users, User, join_through: "users_rooms")
has_many(:children, Room)
belongs_to(:father, Room, foreign_key: :father_id)
timestamps()
end
@doc false
def changeset(room, attrs) do
room
|> cast(attrs, [:name, :depth, :description, :public, :father_id])
|> foreign_key_constraint(:father_id)
|> validate_required([:name, :depth, :public])
end
end
CRUD :
def create_room(attrs \\ %{}) do
%Room{children: [], father: {}, users: []}
|> Room.changeset(attrs)
|> Repo.insert()
end
Controller :
def create(conn, %{"room" => room_params}) do
with {:ok, %Room{} = room} <- Rooms.create_room(room_params) do
conn
|> put_status(:created)
|> put_resp_header("location", room_path(conn, :create, room))
|> render("show.json", room: room)
end
end
Thank you ![]()
Trending in Questions
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
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
Hello,
I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
Documentation
While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
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
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New
Other Trending Topics
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
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
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Hi everyone!
The first release candidate for the Expert language server project is now available!
We’ve published a press release detai...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #ai
- #elixirconf-us
- #blog-post
- #elixir-ls
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #elixirconf-eu
- #metaprogramming
- #hex










Showing Posts 18 to 9- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
Shenrak
The speed at which you’ve done this amazes me !
Thank you
wojtekmach
Aaaand… it’s fixed! See Handle relation changeset error in one place by qcam · Pull Request #2725 · elixir-ecto/ecto · GitHub by @qcam.
wojtekmach
I’ve reproduced this in ecto test suite, I’ll report this upstream!
wojtekmach
glad it’s fixed!
could you paste your ecto version from mix.lock? (or run:
mix deps | grep ecto:)) If you happen to run on a recent version there’s likely still a bug in ecto.Shenrak
I got it working by puttin
nilinsteand of{}. Coming from javascript it’s still hard thinking in maps.The error is sent by Ecto though, so i assume it’s an Ecto bug
Anyway, thank you both for your help
ps : my ecto version is
{:phoenix_ecto, "~> 3.2"}wojtekmach
btw, you’re defaulting
fatherto tuple{}, you probably meant to write%{}, however for embeds/associationsnilis probably better default. In any case, it’s still curious why you’re getting the error.script
Thats why ecto throws an error. transalate error function expects a tuple.
wojtekmach
I think this is the culprit, there errors should be in the form:
so in this case:
Are you setting the
is invaliderror yourself, or is Ecto setting it (via cast_assoc etc)? If the latter, it seems it’s an Ecto bug. What’s your Ecto version?Shenrak
i’ve put two IO.inspect :
and i have :
followed by the error stacktrace
script
Add
IO.inspectafter|> Room.changeset(attrs)And see what it gives you in the console. After you run this method