Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

P: SDK: folder:getParent() raises error instead of returning nil on root folder

LEGEND ,
Nov 20, 2025 Nov 20, 2025

The SDK call folder:getParent() raises the error "?:0: attempt to index field 'parent' (a nil value)" when called on the root folder of some catalogs on Windows -- it should return nil instead. To reproduce on LR 15.0.1 / Windows 11 ARM and Windows 11 Intel:

 

1. Download and uncompress this catalog folder:

https://www.dropbox.com/scl/fi/t1gksh5hw2ov8g48tcca6/folder-getparent-bug.2025-11-20.zip?rlkey=kxqi5...

 

2. Move the file "folder-getparent-bug.lua" from the catalog folder to the LR Scripts folder.

 

3. Start LR and open the catalog.

 

4. In the Scripts menu, invoke "folder-getparent-bug".  Observe this output:

johnrellis_0-1763681291191.png

 

When tested on Mac OS 15.7.1, no error occurs:

johnrellis_1-1763681491243.png

 

 Note that on Mac, the call to folder:getParent() returns 0 results rather than nil (though in most contexts, there's no difference).

 

 

Bug Unresolved
TOPICS
SDK , Windows
164
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
5 Comments
Community Expert ,
Nov 23, 2025 Nov 23, 2025

No idea! But I'll give a guess!

I'm guessing it's platform related. Maybe the root folder raises the error cos the internal parent field is nil. 

Try checking if a folder parent exists before callniiig the get parent. 

 

Something like

 

local parent = nil
if folder.parent then
parent = folder:getParent()
end


Maybe this will help with root folders and maintain compatibility across Windows and Mac.

 

If this works let us know - we can move the discussion to the bugs section and get traction there.

Translate
Report
LEGEND ,
Nov 23, 2025 Nov 23, 2025

[This post contains formatting and embedded images that don't appear in email. View the post in your Web browser.]

 

"local parent = nil
if folder.parent then
parent = folder:getParent()"

 

The field "parent" isn't defined for LrFolder objects.  Accessing any undefined field always returns nil, as this example shows:

 

johnrellis_0-1763924518542.png

 

Translate
Report
LEGEND ,
Nov 23, 2025 Nov 23, 2025

"we can move the discussion to the bugs section and get traction there."

 

@Rikk Flohr: Photography can correct me, but I believe he moved this from Bugs to Discussions until/if the developers confirm they can reproduce this bug.

Translate
Report
Community Expert ,
Nov 23, 2025 Nov 23, 2025

Oh right - sorry I'm no expert in this stuff but I'm trying to learn and help out 

Can you test this and see if it's working? 

 

local function safeGetParent(folder)
    local ok, parent = pcall(function()
        return folder:getParent()
    end)

    if ok then
        return parent  -- either a folder object or nil
    else
        return nil     -- getParent exploded so we treat it as no parent
    end
end

-- Example usage
local folder = catalog:getActiveSources()[1]
local parent = safeGetParent(folder)

if parent then
    LrLogger("debug"):trace("Parent is " .. parent:getPath())
else
    LrLogger("debug"):trace("No parent folder")
end

 

Translate
Report
LEGEND ,
Nov 24, 2025 Nov 24, 2025
LATEST

I use LrTasks.pcall() to catch the erroneous error.  You have to use LrTasks.pcall() rather than the built-in Lua pcall() because of LR's task architecture.  LrTasks.pcall() is about 4 times as expensive as pcall(), which can be noticeable in some circumstances, e.g. traversing very large folder hierarchies.

Translate
Report