dtutils.string: build_substitute_list errors when a metadata field (e.g. rights) has been removed
还没有人认领这个 Issue。
评估
调研方向
从 lib/dtutils/string.lua 中的 build_substitute_list() 开始,然后检查来自 contrib/rename_images.lua 的调用。在移除 rights 元数据字段后,使用 darktable -d lua 重现问题,并验证变量替换和图像重命名在该字段未注册的情况下也能正常工作。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
lib/dtutils/string.lua build_substitute_list() throws when a metadata field it references has been removed from darktable's metadata definitions. Any script using variable substitution (e.g. contrib/rename_images) then fails, regardless of which variables its pattern actually uses.
In darktable 5.x, metadata fields are user-configurable (stored in data.db meta_data). If a user removes e.g. Xmp.dc.rights, the rights field is no longer registered on dt_lua_image_t, and indexing it raises an error rather than returning nil. So the existing guard
image.rights and image.rights or "", -- RIGHTS
doesn't protect against it. The same applies to image.title, image.description, image.creator, image.publisher and image.version_name (lines ~810 and 877–886).
To reproduce
- In the metadata editor preferences, remove the
rights(Xmp.dc.rights) field and restart darktable. - Enable
contrib/rename_images. - Rename any image with any pattern, e.g.
$(EXIF.YEAR)$(EXIF.MONTH)$(EXIF.DAY)_$(SEQUENCE).$(FILE_EXTENSION).
Log (darktable -d lua)
LUA pattern is $(EXIF.YEAR)$(EXIF.MONTH)$(EXIF.DAY)_$(SEQUENCE).$(FILE_EXTENSION)
LUA ERROR : ...urces/share/darktable/lua-scripts/lib/dtutils/string.lua:885: field "rights" not found for type dt_lua_image_t
stack traceback:
[C]: in ?
[C]: in metamethod 'index'
...urces/share/darktable/lua-scripts/lib/dtutils/string.lua:885: in function 'lib/dtutils.string.build_substitute_list'
...es/share/darktable/lua-scripts/contrib/rename_images.lua:144: in upvalue 'do_rename'
...es/share/darktable/lua-scripts/contrib/rename_images.lua:211: in function <...es/share/darktable/lua-scripts/contrib/rename_images.lua:210>
[C]: in ?
Suggested fix
Read the metadata fields through a protected lookup, e.g.
local function get_field(image, field)
local ok, value = pcall(function() return image[field] end)
return (ok and value) and value or ""
end
and use get_field(image, "rights") etc. in the replacements table.
Workaround
Re-add the missing metadata field in the metadata editor preferences.
Platform
- darktable 5.6.0 (Lua API 9.7.0), lua-scripts as bundled with the official macOS package
- macOS 26.6.2, Apple M2
- 主要语言
- Lua
- 星标
- 219
- 派生
- 142
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
darktable-org/lua-scripts 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 63/100
darktable-org/lua-scripts#706 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
darktable-org/lua-scripts#627 · 2 条评论 ·
-
bug
难度 1/5 1 小时以内 新手友好度 65/100
darktable-org/lua-scripts#618 · 3 条评论 ·
-
难度 3/5 1-2 天 新手友好度 52/100
darktable-org/lua-scripts#710 · 3 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
darktable-org/lua-scripts#708 · 1 条评论 ·
查看 darktable-org/lua-scripts 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
-
bug
难度 2/5 1-3 小时 新手友好度 84/100
-
难度 1/5 1 小时以内 新手友好度 90/100
-
[Eco] Egg Config 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
pterodactyl/game-eggs#634 ·
-
Feature Request
难度 1/5 1 小时以内 新手友好度 72/100
Questie/QuestieTrace#33 ·