Skip to main content
Björn Engelke
Participating Frequently
October 23, 2026
Open for Voting

SDK: getTargetPhotos() and photo keywords return stale/incorrect state immediately after importing photos

Immediately after importing new photos into Lightroom Classic, the SDK appears to expose an inconsistent or stale catalog state to plug-ins.

In my case, two problems occur at the same time:

  1. catalog:getTargetPhotos() returns only one photo regardless of the actual selection in Lightroom.

  2. Keywords that have just been assigned to the newly imported photos are not reliably available to the plug-in through photo:getRawMetadata("keywords").

Closing and restarting Lightroom Classic immediately fixes both problems without making any other changes.

After restarting Lightroom, the exact same plug-in code correctly detects the selected photos and the keywords assigned before the restart.

Environment

  • Lightroom Classic: [insert exact version from Help > System Info]

  • Operating system: Windows 11

  • Lightroom Classic SDK plug-in

  • Catalog containing an existing hierarchical keyword structure

  • Newly imported RAW files

Steps to reproduce

  1. Start Lightroom Classic normally.

  2. Import a new set of photos.

  3. After the import has completed, assign existing hierarchical keywords to the newly imported photos.

  4. Select one or more of the newly imported photos.

  5. Run an SDK plug-in which uses:

local catalog = LrApplication.activeCatalog()
local photos = catalog:getTargetPhotos()
  1. For each returned photo, query its assigned keywords:

local keywords = photo:getRawMetadata("keywords")
  1. Change the selection and repeat:

    • select one photo

    • select multiple photos

    • deselect all photos with Ctrl+D

Actual result

Immediately after the import, the SDK behaves incorrectly.

catalog:getTargetPhotos() returns only one photo, regardless of whether:

  • one photo is selected,

  • multiple photos are selected, or

  • no photo is selected.

The returned photo also does not appear to reliably correspond to the currently selected photo. In my tests it appears to be the first photo of the current source/folder.

In addition, keywords that were assigned to the newly imported photos immediately before running the plug-in are not reliably returned by:

photo:getRawMetadata("keywords")

As a result, a plug-in analysing the newly assigned keywords behaves as though the expected metadata were not present.

Expected result

catalog:getTargetPhotos() should reflect the current Lightroom selection as documented:

  • one selected photo → return that photo

  • multiple selected photos → return those photos

  • no selected photos → return the applicable filmstrip/target set according to the SDK behaviour

photo:getRawMetadata("keywords") should immediately return the keywords currently assigned to the photo in the Lightroom catalog.

There should be no need to restart Lightroom after an import before an SDK plug-in can reliably access the selection and keyword metadata.

Workaround / important observation

Close Lightroom Classic completely and start it again.

After restarting Lightroom:

  • catalog:getTargetPhotos() returns the correct photos again.

  • photo:getRawMetadata("keywords") returns the previously assigned keywords correctly.

  • The plug-in works as expected without changing the catalog, keywords, photos, or plug-in code.

This makes the issue highly reproducible as a post-import catalog/UI/SDK state problem rather than a problem with the plug-in's parsing logic.

Example from the plug-in

The plug-in analyses aviation metadata stored in hierarchical Lightroom keywords.

For example, an aircraft may have a keyword such as:

Flugzeug Hersteller
└─ Boeing
└─ Boeing F/A-18E Super Hornet
└─ BA-6 BuNo 165539 #1486/E012 Boeing F/A-18E Super Hornet

The plug-in reads the assigned keywords using:

local keywords = photo:getRawMetadata("keywords")

and derives:

Registration: BA-6
MSN: 1486/E012

It also reads airport keywords such as:

Flughafen
└─ ETSN Fliegerhorst Neuburg

Immediately after importing photos and assigning these keywords, the plug-in may receive only one unexpected photo and/or fail to see the newly assigned keywords.

After restarting Lightroom Classic, the same photos are processed correctly and the same keywords are returned correctly.

Additional notes

This is particularly problematic for workflow plug-ins because the natural workflow is:

Import → assign keywords → run plug-in

Requiring Lightroom Classic to be restarted after every import is not a practical workaround.

The fact that both the target-photo state and newly assigned keyword metadata become correct after a restart suggests that some post-import catalog/UI state is not being synchronised with the SDK correctly.

I can provide a minimal test plug-in that logs:

catalog:getTargetPhoto()
catalog:getTargetPhotos()
catalog:getMultipleSelectedOrAllPhotos()
photo:getRawMetadata("keywords")

before and after restarting Lightroom if that would help reproduce the issue.

    1 reply

    johnrellis
    Legend
    October 23, 2026

    Unfortunately, I’m not able to reproduce this using the script below run from the Scripts menu.  If you run the script instead of your plugin, do you get the same misbehavior?  If the script doesn’t provoke the bug, then please zip up the plugin folder and attach the .zip file here. Also, Please do the LR menu command Help > System Info, click the Copy button in the upper right corner, and paste into your reply here, so we can see exactly which versions of hardware and software LR thinks you're running and important LR options that are set.

     

    To install this script, save it to the file “import-test.lua” and place the file in the Scripts subfolder of the Lightroom settings folder. To navigate to the Lightroom settings folder, click Preferences > Presets > Show All Other Lightroom Presets.  After placing the script in the Scripts subfolder, restart LR and then invoke the Scripts menu (right end of the top menu bar).

     

    import "LrTasks".startAsyncTask (function ()
    local catalog = import "LrApplication".activeCatalog ()
    local photos = catalog:getTargetPhotos ()

    local s = "Number of photos: " .. #photos .. "\n"
    for _, photo in ipairs (photos) do
    local fileName = import "LrPathUtils".leafName (photo.path)
    local keywords = photo:getRawMetadata ("keywords")
    s = s .. fileName .. " keywords: " .. #keywords .. "\n"
    end

    import "LrDialogs".message ("Selection", s)
    end)

     

    Translate