SDK: Undo does not restore a GPS position set with setRawMetadata in the same withWriteAccessDo as a text field
When a plug-in sets a photo's GPS position and one of its text fields (city, country, location or title) in the same catalog:withWriteAccessDo call, Edit › Undo restores the text field but not the GPS position. The new GPS position stays in the catalog, also after quitting and reopening Lightroom Classic. Written in separate withWriteAccessDo calls, or on different photos, both are restored correctly.
Lightroom Classic Version Number
16.0.1
OS Version Number
macOS 27.2.1 (Apple silicon). Address Lookup turned off in Catalog Settings › Metadata. Not tested on Windows.
Camera Model
Not camera-specific: reproduced with a JPEG and with a Sony ARW raw file.
Step-by-step Reproduction Instructions
- Create the "Undo Repro" plug-in from the four files below and add it with File › Plug-in Manager… › Add.
- File › New Catalog…, import one photo, select it.
- Library › Plug-in Extras › 1. Set start values (sets city "Start City", then GPS 10, 20, in two separate writes).
- Library › Plug-in Extras › 2. Write city and GPS (sets city "Test City" and GPS 10.004, 20.004 in one write).
- Edit › Undo Write city and GPS, once.
- Library › Plug-in Extras › 3. Show values.
Expected Result
City: Start City, GPS: 10.0000, 20.0000.
Actual Result
City: Start City, GPS: 10.0040, 20.0040. The city is restored, the GPS position is not. The same values are shown after quitting and reopening Lightroom Classic. The Metadata panel agrees: after step 3 it shows GPS 10°0'0" N 20°0'0" E, after step 4 and still after the Undo 10°0'14.4" N 20°0'14.4" E.
Variations, each written in a single withWriteAccessDo, followed by one Undo:
| Written | After Undo |
|---|---|
| GPS only | restored |
| GPS altitude only | restored |
| GPS and GPS altitude | both restored |
| City, then GPS | city restored, GPS not restored |
| GPS, then city | city restored, GPS not restored |
| Country and GPS | country restored, GPS not restored |
| Location and GPS | location restored, GPS not restored |
| Title and GPS | title restored, GPS not restored |
Plug-in field (setPropertyForPlugin) and GPS | both restored |
| City on photo A, GPS on photo B | both restored |
| City, then GPS and GPS altitude cleared (set to nil) | city restored, GPS and altitude stay cleared |
The problem shows only when the GPS position (or GPS altitude) and a text field change on the same photo within one write. Workaround: write the GPS position and altitude in a separate withWriteAccessDo call.
The plug-in (folder UndoRepro.lrdevplugin)
Info.lua
return {
LrSdkVersion = 10.0,
LrToolkitIdentifier = "com.example.undorepro",
LrPluginName = "Undo Repro",
LrLibraryMenuItems = {
{ title = "1. Set start values", file = "SetStartValues.lua", enabledWhen = "photosSelected" },
{ title = "2. Write city and GPS", file = "WriteCityAndGps.lua", enabledWhen = "photosSelected" },
{ title = "3. Show values", file = "ShowValues.lua", enabledWhen = "photosSelected" },
},
}
SetStartValues.lua
local LrApplication = import "LrApplication"
local LrTasks = import "LrTasks"
LrTasks.startAsyncTask(function()
local catalog = LrApplication.activeCatalog()
local photo = catalog:getTargetPhoto()
catalog:withWriteAccessDo("Set start city", function()
photo:setRawMetadata("city", "Start City")
end, { timeout = 10 })
catalog:withWriteAccessDo("Set start GPS", function()
photo:setRawMetadata("gps", { latitude = 10, longitude = 20 })
end, { timeout = 10 })
end)
WriteCityAndGps.lua
local LrApplication = import "LrApplication"
local LrTasks = import "LrTasks"
LrTasks.startAsyncTask(function()
local catalog = LrApplication.activeCatalog()
local photo = catalog:getTargetPhoto()
catalog:withWriteAccessDo("Write city and GPS", function()
photo:setRawMetadata("city", "Test City")
photo:setRawMetadata("gps", { latitude = 10.004, longitude = 20.004 })
end, { timeout = 10 })
end)
ShowValues.lua
local LrApplication = import "LrApplication"
local LrDialogs = import "LrDialogs"
local LrTasks = import "LrTasks"
LrTasks.startAsyncTask(function()
local photo = LrApplication.activeCatalog():getTargetPhoto()
local gps = photo:getRawMetadata("gps")
local gpsText = gps and string.format("%.4f, %.4f", gps.latitude, gps.longitude) or "none"
LrDialogs.message("Undo Repro", "City: " .. tostring(photo:getFormattedMetadata("city")) .. "\nGPS: " .. gpsText)
end)
