ash-project / ash-project/ash

Not selecting an embed makes query blow up

Open
#1,233 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Elixir
Stars
2.5k
Forks
422
Avg merge
23h 26m
Merged PRs (30d)
46

Description

**Describe the bug**
If you don't select the embed, the query blows up.

**To Reproduce**
```
iex(5)> Safari.Virtual.CesiumAsset |> Ash.Query.select(:id) |> Ash.stream!() |> Stream.run()
[debug] QUERY OK source="cesium_assets" db=4.3ms queue=0.1ms idle=1937.1ms
SELECT c0."id" FROM "cesium_assets" AS c0 ORDER BY c0."id" LIMIT $1 [251]
↳ anonymous fn/3 in AshPostgres.DataLayer.run_query/2, at: lib/data_layer.ex:749
** (KeyError) key :__metadata__ not found in: #Ash.NotLoaded<:attribute, field: :cesium_bucket_credentials>
(ash 3.0.7) lib/ash.ex:1703: Ash.load/3
(ash 3.0.7) lib/ash/type/type.ex:1216: anonymous fn/2 in Ash.Type.splicing_nil_values/2
(ash 3.0.7) lib/ash/actions/read/read.ex:1349: anonymous fn/7 in Ash.Actions.Read.load_through_attributes/7
(elixir 1.16.3) lib/enum.ex:4839: Enumerable.List.reduce/3
(elixir 1.16.3) lib/enum.ex:2582: Enum.reduce_while/3
(ash 3.0.7) lib/ash/actions/read/read.ex:1301: anonymous fn/8 in Ash.Actions.Read.load_through_attributes/7
(elixir 1.16.3) lib/enum.ex:4839: Enumerable.List.reduce/3
(elixir 1.16.3) lib/enum.ex:2582: Enum.reduce_while/3
(ash 3.0.7) lib/ash/actions/read/read.ex:259: Ash.Actions.Read.do_run/3
(ash 3.0.7) lib/ash/actions/read/read.ex:66: anonymous fn/3 in Ash.Actions.Read.run/3
(ash 3.0.7) lib/ash/actions/read/read.ex:65: Ash.Actions.Read.run/3
(ash 3.0.7) lib/ash.ex:1845: Ash.read/2
(ash 3.0.7) lib/ash.ex:1804: Ash.read!/2
(ash 3.0.7) lib/ash/actions/read/stream.ex:45: anonymous fn/5 in Ash.Actions.Read.Stream.do_stream/4
(elixir 1.16.3) lib/stream.ex:1626: Stream.do_resource/5
(elixir 1.16.3) lib/stream.ex:690: Stream.run/1
iex:5: (file)
```

**Expected behavior**
Thing not go boom and I can select only ID

**Runtime**
- `"ash": {:hex, :ash, "3.0.7", "6c37e092f53b1b21eb89596f600a652b2a601f84378f44fd5dd1cdec72eb1cc2"`

**Additional context**
Add any other context about the problem here.

Contributor guide

Open the contributing guide

Research direction

Run the provided IEx reproduction and start with lib/data_layer.ex:749, then trace the failure through lib/ash/actions/read/read.ex and lib/ash.ex. Done means Ash.stream! with Ash.Query.select(:id) completes without the KeyError when the embed is not selected.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir, postgresql
Domain
backend, database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.