In Blender 5.0, the compositing node tree system was changed to work more like any other node group. This means there's no more "Compositing output" node, but rather a regular group output node.
The problem is, creating the group output node with Python and linking it to an image output fails to set the socket type, and we get an invalid connection.
import bpy
node_tree = bpy.data.node_groups.new(name="COMP", type="CompositorNodeTree")
bpy.context.scene.compositing_node_group = node_tree
n_img = node_tree.nodes.new("CompositorNodeImage")
n_comp = node_tree.nodes.new("NodeGroupOutput")
node_tree.links.new(n_img.outputs["Image"], n_comp.inputs[0])
This results in the rendered image being black.
The weird thing is that if we manually remove the connection and create it again by hand in the UI, the output correctly detects the socket type:
So how can I fix this issue and create a valid Image input on the compositor group output node?
From a similar question about Geometry nodes, the solution was to give the group output node itself an output for some reason, however running n_comp.outputs.new("NodeSocketColor", "Image") gives me RuntimeError: Error: Cannot add socket to built-in node


