"attribute is read-only" error when trying to set a PointerProperty of a Shader Node

I’m working on a addon that makes use of custom node groups that has a Pointer property that holds a specific custom class type.
like that:

class BM_ShaderNode_mask_texture(bpy.types.ShaderNodeCustomGroup):
    ... [some other code]
    mask_texture: bpy.props.PointerProperty(name="mask texture", type=MaskTexture, update=update_node_tree)
    ... [the rest of the code]

This is the class type it’s refers to: class MaskTexture (bpy.types.PropertyGroup):

I want to set this Proeprty from somewhere else, which should be simple, apparently, but when I try to do it, I get the following error:
AttributeError: bpy_struct: attribute "mask_texture" from "BM_ShaderNode_mask_texture" is read-only

It’s weird, I haven’t come across this anywhere else, I tried changing the Property type to Object, and it worked great, for some reason it only happens in this specific situation.

I would appreciate it if someone could help me.

I did a quick test, implementing a PointerProperty pointing to a PropertyGroup from a *NodeCustomGroup and it works… So the error is not in the code you’re providing.

You’re probably doing something in another function, perhaps even outside the ShaderNodeCustomGroup; that tries to change its mask_texture into something else.

You can’t reassign a pointerproperty once it has been defined. What you want to do is assign the pointerproperty attributes.

instead of

my_group.mask_texture = my_other_group.mask_texture

do

my_group.mask_texture.my_attr = my_other_group.mask_texture.my_attr
my_group.mask_texture.my_other_attr = my_other_group.mask_texture.my_other_attr
# etc.