Skip to content

Regression in map/2 with left join returning %{field: nil} instead of nil in Ecto 3.13.1 #4622

@halfdan

Description

@halfdan

Elixir version

Elixir 1.18.2 (compiled with Erlang/OTP 27)

Database and Version

PostgreSQL 16

Ecto Versions

3.13.1

Database Adapter and Versions (postgrex, myxql, etc)

postgrex

Current behavior

In 3.13.x the test (see expected behaviour) returns a struct with all keys present, but values set to nil.

     test/asset_test.exs:35
     Assertion with == failed
     code:  assert result == {asset.id, nil}
     left:  {asset.id, %{id: nil, name: nil}}
     right: {asset.id, nil}

Expected behavior

Unclear - but it's a breaking change.

The following test passes in 3.12.x:

test "Ecto 3.12.x: left join map/2 returns nil when join is nil" do
  asset = insert(:file)

  result =
    Asset
    |> from(as: :asset)
    |> join(:left, [asset: a], parent in Asset, on: a.parent_id == parent.id, as: :parent)
    |> where([asset: a], is_nil(a.parent_id) and a.id == ^asset.id)
    |> select([a, p], {a.id, map(p, [:id, :name])})
    |> Repo.one!()

  assert result == {asset.id, nil}
end

(the left joined parent does not exist so is nil)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions