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:
-
catalog:getTargetPhotos()returns only one photo regardless of the actual selection in Lightroom. -
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
-
Start Lightroom Classic normally.
-
Import a new set of photos.
-
After the import has completed, assign existing hierarchical keywords to the newly imported photos.
-
Select one or more of the newly imported photos.
-
Run an SDK plug-in which uses:
local catalog = LrApplication.activeCatalog()
local photos = catalog:getTargetPhotos()-
For each returned photo, query its assigned keywords:
local keywords = photo:getRawMetadata("keywords")-
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 HornetThe plug-in reads the assigned keywords using:
local keywords = photo:getRawMetadata("keywords")and derives:
Registration: BA-6
MSN: 1486/E012It also reads airport keywords such as:
Flughafen
└─ ETSN Fliegerhorst NeuburgImmediately 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.
