Page MenuHome

bpy.context.scene incorrect information
Closed, InvalidPublic


System Information
Operating system: Ubuntu 18.04.3 LTS

Blender Version
Broken: blender-2.80-linux-glibc217-x86_64
Broken: blender-2.81-125257758007-linux-glibc217-x86_64

Short description of error
I discovered this issue when testing with the Blender API in 2.80 but I could reproduce it in 2.81:
It seems that when you trigger a custom operator from a custom "panel button", bpy.context.scene will not update correctly after an immediate scene change by setting bpy.context.window.scene. Although I noticed that if you call the operator directly, for example by searching in the search window, it works just fine.

Code in the operator:

# The original script
for scene in context.blend_data.scenes:
    context.window.scene = scene

Exact steps for others to reproduce the error
1 ) Download test blend file

2 ) Hit "Run Script" in the Text Editor
3 ) Open Scene tab in Properties if it isn't already open
4 ) Hit "Change scenes and print" under "Scene Changer"
5 ) Hit space to open search window, search for "change scenes and print" and click it

Result in console:



Event Timeline

Bastien Montagne (mont29) changed the task status from Unknown Status to Invalid.Nov 15 2019, 5:25 PM
Bastien Montagne (mont29) claimed this task.

Yep, you need to ensure update is effective then, see

We do not handle user support on this tracker, only bug reports. User forums like or and our devtalk should be used for that matter.

Ok thanks, I will keep that gotchas' page in mind, and ask before in those pages when possible.

@Bastien Montagne (mont29) I tested it but it seems that even with bpy.context.view_layer.update() the wrong behavior can still be reproduced, am I missing something? Also I don't understand why it works when the operator is called directly with and without the manual update and when called from a panel it doesn't.

Bastien Montagne (mont29) changed the task status from Invalid to Unknown Status.Nov 18 2019, 12:09 PM
Bastien Montagne (mont29) lowered the priority of this task from 90 to Normal.

The issue is related to the specific context of the Properties editor. If you add the panel to e.g. 3D view it works as expected, and if you call the operator from the Properties window it also fails.

Issue is that Properties space has its own 'current scene' storage, which is returned from its context, and that gets updated on UI update, not on depsgraph update (as is the case for 'normal' context from other spaces).

@Campbell Barton (campbellbarton) would not consider this a bug, more like some internal limitation?

@Bastien Montagne (mont29) So basically the solution is to move the panel out of the Properties editor or write a modal (timer event perhaps?) according to the docs... Any chance of having a way to manually force to update the depsgraph info for Properties editor in the future without resorting to the hack?

The issue here is not the depsgraph update (which is done through the view_layer.update() call), but the UI update (specifically the Properties editor update), for which afaik we have no direct way to trigger from python…

Jeroen Bakker (jbakker) closed this task as Invalid.Mon, Jan 13, 4:37 PM
Jeroen Bakker (jbakker) claimed this task.
Jeroen Bakker (jbakker) edited projects, added Python; removed Tracker Curfew.

This issue seems like a feature request. The system works as intended, but there are limitations what needs development.