Selecting a field whose type is an embedded resource raises "not found in resource lookup"

未关闭
#23 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
backend

调研方向

Start in lib/ash_lua/fields.ex, especially select_for_type/3 around lines 254–257, and trace how ctx.lookup is built from resource_lookup/1 and how the manifest stores embedded definitions in manifest.types. Reproduce with the listed embedded attribute, union, or array case and inspect selection of a sub-field. Done means selecting embedded values returns them without lookup errors, with the suggested default public attributes and no extra select or load.

由索引模型根据 Issue 内容生成。

描述

Seen on 0.2.3 and still on main (878d144e).

A field whose type is, or contains, an embedded resource cannot be selected in fields. This covers an :embedded_resource attribute, a union whose members are embedded resources, and {:array, Embedded}. The select raises:

** (RuntimeError) Resource MyApp.SomeEmbedded not found in resource lookup
    (ash) Ash.Info.Manifest.get_resource!/2
    (ash_lua) AshLua.Fields.select_for_type/3   # lib/ash_lua/fields.ex ~254-257
Cause

Ash.Info.Manifest.Generator puts embedded resources in manifest.types, not manifest.resources. AshLua builds ctx.lookup from resource_lookup/1 only. Then select_for_type/3 matches kind in [:resource, :embedded_resource] and calls Manifest.get_resource!(ctx.lookup, mod), which fails for the embedded module.

Repro
  1. Take a resource with an attribute profil of an embedded type (or a union of embedded types), exposed through a read action on the Lua surface.
  2. Run x.list({ fields = { "id", "profil" } }), or select a sub-field of it.
  3. It raises instead of returning the embedded value.
Suggested fix

Treat an embedded resource like a typed map. Take its definition from manifest.types (type.resource), default to all public attributes, and allow subselection. Embedded values are already loaded with the parent, so select = [] and load = [] for them.

Workaround we use

We pass our own manifest: to AshLua.Eval.run/2, with each embedded type rewritten to kind: :map.

主要语言
Elixir
星标
15
派生
5
平均合并
2 小时 16 分钟
30 天内合并 PR
1

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

ash-project/ash_lua 的其他 Issue

查看 ash-project/ash_lua 的全部 Issue

相似的 Issue

更多 Elixir Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。