bpy.utils.unregister_module doesn't unregister classes of submodules #50052

Closed
opened 2016-11-16 17:58:05 +01:00 by Alexander Romanov · 10 comments

Short description of error
bpy.utils.register_module register classes from submodules correctly, but bpy.utils.unregister_module doesn't unregister them.

I've attached example of a simple addon to check this.

Exact steps for others to reproduce the error

Download and unpack custom_scripts.zip

  • Set Scripts path to point to the root directory called custom_scripts press Save User Settings
  • Press F8
  • Enable Addon called Test
  • Clear Scripts field and Save User Settings
  • Press F8
  • You will see that the Test panel on the Render tab is still present. You also can find the corresponding class in bpy.types

If you will uncomment bpy.utils.unregister_class(RenderTestPanel) in ui_render.py and retry all steps, you will see the correct behavior

Probably it's an expected behavior

**Short description of error** `bpy.utils.register_module` register classes from submodules correctly, but `bpy.utils.unregister_module` doesn't unregister them. I've attached example of a simple addon to check this. **Exact steps for others to reproduce the error** Download and unpack [custom_scripts.zip](https://archive.blender.org/developer/F401769/custom_scripts.zip) - Set `Scripts` path to point to the root directory called `custom_scripts` press `Save User Settings` - Press F8 - Enable Addon called `Test` - Clear `Scripts` field and `Save User Settings` - Press F8 - You will see that the `Test` panel on the `Render` tab is still present. You also can find the corresponding class in bpy.types # If you will uncomment `bpy.utils.unregister_class(RenderTestPanel)` in `ui_render.py` and retry all steps, you will see the correct behavior Probably it's an expected behavior
Author
Member

Changed status to: 'Open'

Changed status to: 'Open'
Author
Member

Added subscriber: @AlexanderRomanov

Added subscriber: @AlexanderRomanov

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2016-11-18 12:46:54 +01:00

I do not see any unexpected behavior here? When you clear script field, you just prevents Blender any further access to that addon, so it obviously cannot unregister or re-register that addon correctly anymore. Henceforth, all classes it defined during its last registration remain alive until next start of Blender.

I do not see any unexpected behavior here? When you clear script field, you just prevents Blender any further access to that addon, so it obviously cannot unregister or re-register that addon correctly anymore. Henceforth, all classes it defined during its last registration remain alive until next start of Blender.
Author
Member

If bpy.utils.register_module calls register_class for each submodule class, bpy.utils.unregister_module must call unregister_class for that submodules. This is what I am expecting. After clearing Scripts unregister_class must be invoked from unregister_module, which is in memory currently; and yes, register will fail. But we see, that unregister_class is not called by unregister_module, because the pannel is still present.

def unregister_module(module, verbose=False):
    if verbose:
        print("bpy.utils.unregister_module(%r): ..." % module)
    for cls in _bpy_module_classes(module, is_registered=True):
        if verbose:
            print("    %r" % cls)
        try:
            unregister_class(cls)
        except:
            print("bpy.utils.unregister_module(): "
                  "failed to unregistering class %r" % cls)
            import traceback
            traceback.print_exc()
    if verbose:
        print("done.\n")

You can see invocation of unregister_class, but generator _bpy_module_classes returns nothing. Seems that the issue is in _bpy_types.TypeMap, or I missed something.

PS Now it seems that you don't have to call register_class for all your classes, but you have to call unregister_class

If `bpy.utils.register_module` calls `register_class` for each submodule class, `bpy.utils.unregister_module` must call `unregister_class` for that submodules. This is what I am expecting. After clearing `Scripts` `unregister_class` must be invoked from `unregister_module`, which is in memory currently; and yes, register will fail. But we see, that `unregister_class` is not called by `unregister_module`, because the pannel is still present. ``` def unregister_module(module, verbose=False): if verbose: print("bpy.utils.unregister_module(%r): ..." % module) for cls in _bpy_module_classes(module, is_registered=True): if verbose: print(" %r" % cls) try: unregister_class(cls) except: print("bpy.utils.unregister_module(): " "failed to unregistering class %r" % cls) import traceback traceback.print_exc() if verbose: print("done.\n") ``` You can see invocation of `unregister_class`, but generator `_bpy_module_classes` returns nothing. Seems that the issue is in _bpy_types.TypeMap, or I missed something. PS Now it seems that you don't have to call `register_class` for all your classes, but you have to call `unregister_class`

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'

OK, confirmed the issue and found the culprit: in reload case (F8), TypeMap is cleared before calling unregister for all active addons, which means all calls to unregister_module will fail.

This was not a visible issue, because reloading that happens immediately after would silently unregister classes already existing, so could only be detected when an addon had gone missing in between.

Will just clear TypeMap after unregistering all addons, see no reason to do it before hand anyway.

OK, confirmed the issue and found the culprit: in reload case (F8), TypeMap is cleared before calling unregister for all active addons, which means all calls to unregister_module will fail. This was not a visible issue, because reloading that happens immediately after would silently unregister classes already existing, so could only be detected when an addon had gone missing in between. Will just clear TypeMap after unregistering all addons, see no reason to do it before hand anyway.

This issue was referenced by blender/blender@8f0dc3cef6

This issue was referenced by blender/blender@8f0dc3cef6c3f3e02a0a4322cd241cf379e52552

Changed status from 'Open' to: 'Resolved'

Changed status from 'Open' to: 'Resolved'
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender-addons#50052
No description provided.