Avoiding "search for unknown operator" error when unregistering keymaps

I am not sure what is causing this message every time I try to unregister an add-on that defines custom hotkeys / keyboard shortcuts:

search for unknown operator 'CATEGORY_operator_name' , 'CATEGORY_operator_name'
search for unknown operator 'CATEGORY_operator_name' , 'CATEGORY_operator_name'

I have tried multiple register and unregister options: the one listed in this older Add-on Tutorial and methods listed in other add-ons and none of them make this message go away. This is my current test script, anything obviously wrong?

import bpy

bl_info = {
    "name": "Keymap Test",
    "author": "nBurn",
    "location": "Searchbar > Keymap Test",
    "version": (0, 0, 0),
    "blender": (2, 7, 7),
    "description": "Test for adding custom hotkeys",
    "wiki_url": "",
    "category": "Object"
}

print("\nAdd-on loaded:")  # debug
print("keymap_test.py")  # debug


class KeymapTest(bpy.types.Operator):
    bl_idname = 'object.keymap_test_op'
    bl_label = 'Keymap Test'
    bl_description = 'Main class for add-on'
    bl_options = {'REGISTER'}

    def invoke(self, context, event):
        print("KeymapTest invoke method called")
        return {'FINISHED'}


# store keymaps here to access after registration
#addon_keymaps = []


def register():
    print("register function called")
    bpy.utils.register_class(KeymapTest)

    # add keymap entry
    kc = bpy.context.window_manager.keyconfigs.addon
    if kc:
        km = kc.keymaps.new(name='3D View', space_type='VIEW_3D')
        #kmi = km.keymap_items.new(KeymapTest.bl_idname, \
        kmi = km.keymap_items.new('object.keymap_test_op', \
                'NUMPAD_SLASH', 'PRESS', ctrl=True)
        #kmi.properties.total = 3
        #addon_keymaps.append((km, kmi))


def unregister():
    print("unregister function called")

    # remove keymap entry
    '''
    if addon_keymaps:
        for km, kmi in addon_keymaps:
            km.keymap_items.remove(kmi)
        addon_keymaps.clear()
    '''
    kc = bpy.context.window_manager.keyconfigs.addon
    if kc:
        km = kc.keymaps['3D View']
        #kmi = km.keymap_items[KeymapTest.bl_idname]
        kmi = km.keymap_items['object.keymap_test_op']
        km.keymap_items.remove(kmi)

    bpy.utils.unregister_class(KeymapTest)


if __name__ == '__main__':
    register()

Naming convention issue with operator class name ?
class OBJECT_OT_keymap_test_op

Do you have a suggestion for one that would mitigate this? I have tried both the below naming conventions and neither made a difference.

The current convention:
file name: keymap_test.py
bl_label: Keymap Test
main class name: KeymapTest
bl_idname: object.keymap_test_op

Convention that makes the class name overlap the id_name:
file name: keymap_test.py
bl_label: Keymap Test
main class name: OBJECT_OT_keymap_test
bl_idname: object.keymap_test

Right now I am thinking this might be a Blender bug as all the “official” add-ons I’ve tried that uses “keymap_items.new” to add hotkeys have this issue (Node Wrangler, Bool Tool, F2, API Navigator, Edit Linked Library).

It may be a bug in Blender, have you tested this in the latest daily build (master, not blender2.8)?

1 Like

Good point, I should have thought to check that. If this was a bug, it appears to be fixed in a recent 2.79 daily I downloaded (c960804 2018-07-04) as my test script does not produce the error message on unregistering with that version.

Im seeing this same issue in 2.79c f4dc9f9 on osx. I read somewhere that unregistering the addon class before the keys could cause this. tried that changing unregistering of the class always last. Does not help.

I also see this with multiple addons. Does someone now the exact fix for that bug?

PS i also did manual clean of keymap, still see that error “search for unknown operator”

I don’t know which exact revision fixed this bug or what the workaround would be, besides using latest master. The fix was not in 2.79c, so it’s expected to have the error there still.