Elixir version
any
Database and Version
any
Ecto Versions
3.14
Database Adapter and Versions (postgrex, myxql, etc)
any
Current behavior
When Repo.insert_all/3 receives a source query using select: r, it builds the insert column list from the source schema instead of destination. This results in incorrect SQL in case of mapping and ignoring writable: false
Repro:
With those schemas
defmodule InsertSelectSource do
use Ecto.Schema
@primary_key false
schema "insert_select_source" do
field :name, :string
end
end
defmodule InsertSelectRenamed do
use Ecto.Schema
@primary_key false
schema "insert_select_renamed" do
field :name, :string, source: :renamed_name
end
end
defmodule InsertSelectReadOnly do
use Ecto.Schema
@primary_key false
schema "insert_select_read_only" do
field :name, :string, writable: :never
end
end
query = from s in InsertSelectSource, select: s
TestRepo.insert_all(InsertSelectRenamed, query)
Errors with 42703 undefined_column on postgres
query = from s in InsertSelectSource, select: s
TestRepo.insert_all(InsertSelectReadOnly, query)
writes into filed marked as not writable
Expected behavior
destination schema respected
Elixir version
any
Database and Version
any
Ecto Versions
3.14
Database Adapter and Versions (postgrex, myxql, etc)
any
Current behavior
When
Repo.insert_all/3receives a source query usingselect: r, it builds the insert column list from the source schema instead of destination. This results in incorrect SQL in case of mapping and ignoringwritable: falseRepro:
With those schemas
Errors with 42703 undefined_column on postgres
writes into filed marked as not writable
Expected behavior
destination schema respected