darktable-org / darktable-org/lua-scripts
dtutils.string: build_substitute_list errors when a metadata field (e.g. rights) has been removed
まだ誰も着手していません。
- 主要言語
- Lua
- スター
- 219
- フォーク
- 142
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
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
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
lib/dtutils/string.lua の build_substitute_list() から始め、次に contrib/rename_images.lua からの呼び出しを調べます。rights メタデータフィールドを削除した後、darktable -d lua で再現し、そのフィールドが登録されていなくても変数置換と画像の名前変更が機能することを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- lua
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 活発さ
- 活発
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 78/100