import bpy
scene=bpy.context.scene
# Add the compositor nodes correctly for Blender 5.1 via compositing_node_group's interface.
try:
    tree=bpy.data.node_groups.get('Lantern Compositor')
    if tree:
        # create interface sockets if absent
        items=tree.interface.items_tree
        has_in=any(getattr(it,'name','')=='Image' and getattr(it,'in_out','')=='INPUT' for it in items)
        has_out=any(getattr(it,'name','')=='Image' and getattr(it,'in_out','')=='OUTPUT' for it in items)
        if not has_in: tree.interface.new_socket(name='Image',in_out='INPUT',socket_type='NodeSocketColor')
        if not has_out: tree.interface.new_socket(name='Image',in_out='OUTPUT',socket_type='NodeSocketColor')
        tree.nodes.clear()
        gi=tree.nodes.new('NodeGroupInput'); gi.location=(-420,0)
        go=tree.nodes.new('NodeGroupOutput'); go.location=(300,0)
        gl=tree.nodes.new('CompositorNodeGlare'); gl.glare_type='FOG_GLOW'; gl.quality='HIGH'; gl.threshold=1.1; gl.size=7; gl.mix=-0.86; gl.location=(-80,0)
        tree.links.new(gi.outputs.get('Image'),gl.inputs.get('Image'))
        tree.links.new(gl.outputs.get('Image'),go.inputs.get('Image'))
        scene.compositing_node_group=tree
        scene.render.use_compositing=True
        comp='set'
    else: comp='no tree'
except Exception as e: comp='error '+repr(e)
# save, preserve final render settings
scene.render.engine='CYCLES'; scene.render.resolution_x=1536; scene.render.resolution_y=1536; scene.render.resolution_percentage=100; scene.cycles.samples=64; scene.render.filepath='<repo>/apps/console/camping_lantern_final.png'
bpy.ops.wm.save_as_mainfile(filepath='<repo>/apps/console/camping_lantern.blend')
result={'comp':comp,'group':scene.compositing_node_group.name if scene.compositing_node_group else None,'nodes':[(n.name,n.bl_idname) for n in (tree.nodes if tree else [])],'use':scene.render.use_compositing,'engine':scene.render.engine}


error AttributeError("'CompositorNodeGlare' object has no attribute 'glare_type'")