My custom brush turn off autosmooth modifier. Problem with dyntopo

Hello
I wrote such a custom brush

    def shading_is_on_handler(mod, context):
        if bpy.context.scene.is_smooth_shade:
            bpy.ops.object.shade_smooth()
        else:
            bpy.ops.object.shade_flat()

    def disable_other_brushes(but_this_one, context):
        for k, v in context.scene.brush_properties.__annotations__.items():
            if context.scene.brush_properties.get(k) and k is not but_this_one:
                context.scene.brush_properties[k] = False

    def smooth_brush_handler(mod, context):
        if context.scene.brush_properties.is_smooth_brush:
            BrushProperties.disable_other_brushes('is_smooth_brush', context)
            bpy.ops.object.mode_set(mode='SCULPT')
            if not bpy.ops.sculpt.use_dynamic_topology_sculpting:
                bpy.ops.sculpt.dynamic_topology_toggle()
            bpy.ops.wm.tool_set_by_id(name="builtin_brush.Smooth")
            bpy.ops.sculpt.dynamic_topology_toggle()            
            bpy.context.scene.tool_settings.unified_paint_settings.size = 50
            bpy.data.brushes["Smooth"].strength = 0.8
            bpy.context.scene.tool_settings.sculpt.use_smooth_shading = True
        else:
            if bpy.ops.sculpt.use_dynamic_topology_sculpting:
                bpy.ops.sculpt.dynamic_topology_toggle()

            bpy.context.scene.properties.is_smooth_shade = True
            bpy.ops.object.mode_set(mode='OBJECT')  

        for a in [a for a in bpy.context.screen.areas if a.type in ['VIEW_3D', 'PROPERTIES']]:
            a.tag_redraw()

My problem is I don’t know why, turning on this brush, the autosmooth turns off. When I unmark the brush, the autosmooth works back.
Does anyone know why this is happening?
Thanks for help.
Greets
[UPDATE]
I found that the autosmooth crash only happens when I have another brush pressed [written in the same way] and hit another one.
image