Skip to main content
johnrellis
Legend
June 8, 2026

P: SDK: Race condition with photo:applyDevelopPreset() and catalog:updateAISettings()

  • June 8, 2026
  • 4 replies
  • 78 views

If a plugin calls catalog:updateAISettings() immediately after photo:applyDevelopPreset(), the application of the preset is ignored. This bug was introduced in LR 15.3, likely with the background processing of AI commands.

 

To reproduce on LR 15.3 / Mac OS 26.4.1:

 

1. Import the attached preset “_Update Bug.xmp”.

 

2. Put the attached file “updateaisettings-bug.txt” into the LR Scripts folder.

 

3. Go to Develop with a test photo.

 

4. Do Scripts > updateaisettings-bug. Observe that Exposure is not changed (incorrect -- it should change to 4).

 

5. Apply the preset “_Update Bug”. Observe that Exposure changes to 4 (correct).

 

A workaround is to call LrTasks.sleep (0.1) before calling catalog:updateAISettings().

    4 replies

    johnrellis
    Legend
    June 8, 2026

    [View this post in your web browser. It contains formatting and images that don't appear in email.] 

     

    @C.Cella One workaround I use to coordinate with the photo:applyDevelopPreset() is to create a Progress scope within which I summon photo:applyDevelopPreset(). When this parent scope is complete, I trigger the next action.

     

    Any Menu does that -- it uses a progress scope, within which the chosen menu item or preset is applied to all the selected photos. Then outside the scope, catalog:updateAISettings() is applied.

     

    I’ll look into catalog:applyDevelopPreset(), though that will require reworking the code to special-case applying presets as compared to other menu commands.

    C.Cella
    Legend
    June 8, 2026

    catalog:applyDevelopPreset() allows to apply a preset to an array and shows ONLY one scope for the entire process. 
    It also ahs the 4th argument “udpateAISettings” which makes redundant to use catalog:updateAISettings() as a second step (like we had to do before to prevent N scopes to appear)

    I had to do a bit of rewrite of my codes (I have Plug-in that applies presets in simple ways that LrC doesn’t allow)

    This said catalog:applyDevelopPreset() in succession have race conditions and can’t coordinate.

     

    johnrellis
    Legend
    June 8, 2026

    [View this post in your web browser. It contains formatting and images that don't appear in email.]

     

    @C.Cella I haven’t found a reliable “sleep” time for all situations.

     

    That’s the general problem with using sleep to workaround race conditions -- there’s no assurance about whether it workarounds 50%, 90%, or 99.9999% of the races.

    C.Cella
    Legend
    June 8, 2026

    I can’t reply properly.
    I get a red “Something’s Gone wrong” message.


    There seems to be a character limit or something like thatt because I could NOT post in a single reply.

    johnrellis
    Legend
    June 8, 2026

    [View this post in your web browser. It contains formatting and images that don't appear in email.]

    @C.Cella a red “Something’s Gone wrong” message.

     

    That happens to me about once every couple of weeks. I’m guessing there are many different triggers.

    johnrellis
    Legend
    June 8, 2026

    @C.Cella Might be of interest to you.

    C.Cella
    Legend
    June 8, 2026

    I’ve already encountered race conditions with all APIs that themselves provide a progress scope.

    For instance, if one tries to perform photo:applyDevelopPreset() followed by photo:setRawMetadata(), the latter might occur before even the preset was applied.

    In my experience, setting a LrTasks.sleep() is not reliable because, for my “heavily edited” photos, it can take seconds to apply a preset due to various reasons. I haven’t found a reliable “sleep” time for all situations.

    C.Cella
    Legend
    June 8, 2026

    One workaround I use to coordinate with the photo:applyDevelopPreset() is to create a Progress scope within which I summon photo:applyDevelopPreset(). When this parent scope is complete, I trigger the next action.
    In some codes, when I apply settings or presets, I directly read the catalog with SQLite to check for the appearance of history steps, which is the trigger I use to perform the extra action.

     

    I suggested to the team that we be able to observe scopes so that we could coordinate.

     

     

    P.S.

    If you still rely on photo:applyDevelopPreset() in your plug-ins (Any Menu, I guess), then now you can use catalog:applyDevelopPreset(), which presents ONE scope for all the array.

    So, there’s no longer a need to do photo:applyDevelopPreset() and catalog:updateAISettings() as we had to before.