Page MenuHome

bpy.data.libraries.load does not return the right thing (Geometry Nodes, Collections, Shader nodes are fine)
Closed, ResolvedPublicBUG

Description

System Information
Operating system: Windows-10-10.0.19041-SP0 64 Bits
Graphics card: GeForce GTX 750 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 456.71

Blender Version
Broken: version: 3.1.0 Alpha, branch: master, commit date: 2021-12-23 00:38, hash: rB193138779991
Worked: 3.0

Caused by rB0704570721b7: LibLink/Append: Port `bpy.data.libraries.load` to new…

Short description of error
When appending node group with libraries.load, it didn't return a right node group in at the first time

Target node group: General MS 1.0
Get node groups in with: ['General MS 1.0']
Get node groups out with: [bpy.data.node_groups['adjt_switch_geo']]
Return node group <bpy_struct, GeometryNodeTree("adjt_switch_geo") at 0x000001C760C1D608>

Exact steps for others to reproduce the error
Use this script to import a node group, it return the wrong node group in the first time

def get_preset(dir_name, file_name, node_group_name):
    base_dir = os.path.join(bpy.utils.user_resource('SCRIPTS'), 'addons', __folder_name__, 'preset',
                            dir_name, file_name)

    if node_group_name in bpy.data.node_groups:
        preset_node = bpy.data.node_groups[node_group_name]
    else:
        with bpy.data.libraries.load(base_dir, link=False) as (data_from, data_to):
            data_to.node_groups = [name for name in data_from.node_groups if name == node_group_name]

            print('Target node group:',node_group_name)
            print('Get node groups in with:',data_to.node_groups)
        print('Get node groups out with:',data_to.node_groups)

        preset_node = data_to.node_groups[0]
        print('Return node group',preset_node)

    return preset_node

Shader nodes are fine apparently:

  • extract .zip somewhere
  • Open T94338.blend
  • run script

expected output:

Target node group: PricipledBSDF_wrapped
Get node groups in with: ['PricipledBSDF_wrapped']
Get node groups out with: [bpy.data.node_groups['PricipledBSDF_wrapped']]
Return node group <bpy_struct, ShaderNodeTree("PricipledBSDF_wrapped") at 0x7faef0b4d008>

Geo nodes are not:

Target node group: Geo Top Group
Get node groups in with: ['Geo Top Group']
Get node groups out with: [bpy.data.node_groups['Geo In Group']]
Return node group <bpy_struct, GeometryNodeTree("Geo In Group") at 0x000001AA21807008>

Collections dont work as well:

Target collection: foo
Get collections in with: ['foo']
Get collections out with: [bpy.data.collections['bar.001']]
Return collection <bpy_struct, Collection("bar.001") at 0x7fe7a43d8ec8>

Event Timeline

Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Needs Information from User.Dec 23 2021, 1:14 PM

Cannot reproduce in rB00965c98cbf1.

Here is my test scenario:

  • extract .zip somewhere
  • Open T94338.blend
  • run script

expected output:

Target node group: PricipledBSDF_wrapped
Get node groups in with: ['PricipledBSDF_wrapped']
Get node groups out with: [bpy.data.node_groups['PricipledBSDF_wrapped']]
Return node group <bpy_struct, ShaderNodeTree("PricipledBSDF_wrapped") at 0x7faef0b4d008>

Is this not working for you?
If so (and you have another scenario that is not working, please upload an equivalent example to mine - where you just have to open a file and execute the script).

I just try it with the geo nodes( Which work very similar like the example)
Please check the example

Target node group: Geo Top Group
Get node groups in with: ['Geo Top Group']
Get node groups out with: [bpy.data.node_groups['Geo In Group']]
Return node group <bpy_struct, GeometryNodeTree("Geo In Group") at 0x000001AA21807008>
Philipp Oeser (lichtwerk) changed the task status from Needs Information from User to Needs Triage.Dec 23 2021, 4:37 PM
Philipp Oeser (lichtwerk) changed the task status from Needs Triage to Confirmed.Dec 28 2021, 3:11 PM

OK, can confirm now.

Philipp Oeser (lichtwerk) renamed this task from bpy.data.libraries.load did not return a right node group to Geometry Nodes: bpy.data.libraries.load did not return a right node group (shader nodes are fine).Dec 28 2021, 3:12 PM
Philipp Oeser (lichtwerk) triaged this task as High priority.Fri, Jan 14, 11:58 AM

Caused by rB0704570721b7: LibLink/Append: Port `bpy.data.libraries.load` to new….

Will set to High prio since this is a regression and the culprit commit has been identified.

@Bastien Montagne (mont29): mind checking?

Philipp Oeser (lichtwerk) renamed this task from Geometry Nodes: bpy.data.libraries.load did not return a right node group (shader nodes are fine) to bpy.data.libraries.load does not return the right thing (Geometry Nodes, Collections, Shader nodes are fine).Fri, Jan 14, 12:08 PM
Philipp Oeser (lichtwerk) updated the task description. (Show Details)
Bastien Montagne (mont29) changed the subtype of this task from "Report" to "Bug".
Bastien Montagne (mont29) moved this task from Backlog to Blender 3.1 on the Core board.