Error When Trying to Add Custom Node

I am trying to code a simple Python script to add various effects in the compositor. I am wanting to add a custom node group that I have.

This is the script

import bpy


class CompEffects(bpy.types.Panel):
    bl_label = "Comp Effects"
    bl_space_type = 'NODE_EDITOR'
    bl_region_type = 'UI'
    bl_label = "Comp Effects"
    bl_context = "CompositorNodeTree"

    def draw(self, context):
        layout = self.layout

        row = layout.row()
        row.label(text="Camera Effects", icon='CAMERA_DATA')
        
        row = layout.row()
        bpy.ops.node.add_node(type="CompositorNodeGroup", use_transform=True, settings=[{"name":"node_tree", "value":"bpy.data.node_groups['Vignette']"}])

def register():
    bpy.utils.register_class(CompEffects)


def unregister():
    bpy.utils.unregister_class(CompEffects)


if __name__ == "__main__":
    register()

and this is the error

Python: Traceback (most recent call last):
  File "C:\Users\ethan\3D Objects\Blender\Addons\Scripts\Comp Effect_V1_1.blend\Comp Effects", line 18, in draw
  File "C:\Program Files (x86)\Steam\steamapps\common\Blender\3.3\scripts\modules\bpy\ops.py", line 113, in __call__
    ret = _op_call(self.idname_py(), None, kw)
RuntimeError: Calling operator "bpy.ops.node.add_node" error, can't modify blend data in this state (drawing/rendering)

Do I need to make the node inside Python to add it?

1st I would recommend you edit your post so that the entire script is in a single block. Use 3 consecutive grave accent at the beginning and end of your script this makes the overall post much more readable.

2nd it appears as though you are attempting to create a panel class CompEffects(bpy.types.Panel) and using it to run an operation bpy.ops.node.add_node. The draw function of a panel is constantly repeated while the panel is displayed in order to refresh any changes in the panel. This can occur hundreds of times every second.

Given you do not want the system to just continually add a new node every time the panel is re-drawn. You need to create an operator to be used in the panel.

I would highly recommend watching Dr. Sybren Stuval’s scripting for artists series on Blender’s Youtube playlist. While episodes 8-10 are the most relevant to this post the other episodes are very informative and worth watching if you have time.

Blender - YouTube

@nezumi.blend How do you copy paste code so it formats right?