[Bf-committers] Addon's can no longer access context on activation.

Campbell Barton ideasman42 at gmail.com
Thu Dec 20 03:38:58 CET 2012


Recently I've noticed addons using bpy.context.scene when being
imported or in the register() function.

This is really bad practice and will cause inconsistency if the addon
is enabled and a different blend file is loaded.
In the worst case accessing a removed datablock can crash which is
likely if a datablock is stored as a global variable on activation -
object_laplace_lightning.py does this.

I've changed addon loading so that they only get access to a
restricted context which only exposes 'window_manager' - needed for
adding keymaps.


Accessing other attributes now errors out with...

  AttributeError: '_RestrictedContext' object has no attribute 'scene'

The addons distributed with blender don't do this but some contrib
addons do, so they will need updating
(release/scripts/addons_contrib).

----
    add_mesh_clusters
    gyes
    io_atomblend_utilities
    io_export_marmalade
    io_import_LRO_Lola_MGS_Mola_img
    io_import_lipSync_Importer
    mesh_edgetools
    mesh_fiber
    mesh_show_vgroup_weights
    node_categories
    object_laplace_lightning
    online_mat_lib
    sequencer_extra_actions
    space_view3d_quickPrefs

If any devs want some help updating their addons you can ask on
bf-python mailing list, though in all cases I've seen its quite
straightforward.

-- 
- Campbell


More information about the Bf-committers mailing list