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

Offen Anfängerfreundlich
#716 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
78/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
lua
Bereich
tooling

Rechercherichtung

Beginne in lib/dtutils/string.lua bei build_substitute_list() und untersuche dann den Aufruf aus contrib/rename_images.lua. Reproduziere das Problem mit darktable -d lua, nachdem du das Metadatenfeld rights entfernt hast, und überprüfe, dass Variablensubstitution und das Umbenennen von Bildern funktionieren, ohne dass das Feld registriert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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
Vorherrschende Sprache
Lua
Sterne
219
Forks
142
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus darktable-org/lua-scripts

Alle Issues in darktable-org/lua-scripts

Ähnliche Issues

Weitere Issues zu Lua

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.