dtutils.string: build_substitute_list errors when a metadata field (e.g. rights) has been removed

未关闭 适合新手
#716 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
lua
领域
tooling

调研方向

从 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

  1. In the metadata editor preferences, remove the rights (Xmp.dc.rights) field and restart darktable.
  2. Enable contrib/rename_images.
  3. 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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

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

darktable-org/lua-scripts 的其他 Issue

查看 darktable-org/lua-scripts 的全部 Issue

相似的 Issue

更多 Lua Issue

把新 issue 发到你的邮箱

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