Page MenuHome

Fix T72338 : Make `bpy.extra.object_data_add` callable when context has no space_data
ClosedPublic

Authored by Frank Bessou (fbessou) on Dec 10 2019, 4:18 PM.

Details

Summary

When calling this function in a python script, the context's
space_data can be None, making this condition raise an AttributeError.
This is the case when the running the script through '-P' argument

One solution could be for the user to call this helper with a custom
context with a stub space_data but from the user's perspective it is not
obvious that this is required just by watching at the
documentation or function signature.

All other functions which are using the space_data in this file first
check for the space_data existence before testing it's type. So adding
it here add some consistency.

Fixes T72338.

Diff Detail

Repository
rB Blender
Branch
object-data-add-in-python-script (branched from master)
Build Status
Buildable 5958
Build 5958: arc lint + arc unit

Event Timeline

Frank Bessou (fbessou) retitled this revision from Fix T72338: Make `bpy.extra.object_data_add` when context has no space_data to Fix T72338 : Make `bpy.extra.object_data_add` when context has no space_data.Dec 10 2019, 4:18 PM
Frank Bessou (fbessou) edited the summary of this revision. (Show Details)
Frank Bessou (fbessou) retitled this revision from Fix T72338 : Make `bpy.extra.object_data_add` when context has no space_data to Fix T72338 : Make `bpy.extra.object_data_add` callable when context has no space_data.
This comment was removed by Frank Bessou (fbessou).
Frank Bessou (fbessou) edited the summary of this revision. (Show Details)Dec 10 2019, 4:23 PM
This revision is now accepted and ready to land.Dec 11 2019, 4:21 PM

Eeeh, look like this has already been fixed, current code in master is:

space_data = context.space_data
if space_data and space_data.type != 'VIEW_3D':
    space_data = None

if space_data:
    if space_data.local_view:
        obj_new.local_view_set(space_data, True)

thanks, closing.