Skip to main content
Participant
Nov 21, 2026 2:09 PM UTC
Open for Voting

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

  1. Create the "Undo Repro" plug-in from the four files below and add it with File › Plug-in Manager… › Add.
  2. File › New Catalog…, import one photo, select it.
  3. Library › Plug-in Extras › 1. Set start values (sets city "Start City", then GPS 10, 20, in two separate writes).
  4. Library › Plug-in Extras › 2. Write city and GPS (sets city "Test City" and GPS 10.004, 20.004 in one write).
  5. Edit › Undo Write city and GPS, once.
  6. 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)

3 replies

johnrellis
Legend
Nov 21, 2026 7:22 PM UTC

I see the same misbehavior with the script WriteCityAndGps.lua posted above.

Translate
Lemming77Author
Participant
Nov 28, 2026 9:01 AM UTC

Hello John,

Thanks for testing it, good to know it's not just me ;)

Which OS are you on (macOS or Windows), and which Lightroom Classic version? I could only test on macOS with 16.0.1.

To work around this, I use a two-step process:
1. one withWriteAccessDo for the text fields (city, country, title…)
2. a second withWriteAccessDo for GPS and altitude only

I give both writes the same name and do nothing in between (no yield). LR then merges them into one action, so the user can undo everything in one step.

However, I'm not sure this is a robust approach, and I haven't tested it on Windows, so it may behave differently there.

Translate
johnrellis
Legend
Nov 28, 2026 4:47 PM UTC

I tested on LR 16.0.1 / Mac OS 26.6.2.

Translate