bpy.context.scene incorrect information #71542

Closed
opened 2019-11-13 15:19:54 +01:00 by mike w. · 15 comments

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:

for scene in context.blend_data.scenes:

context.window.scene = scene
print(context.scene.name)```


**Exact steps for others to reproduce the error**
1 ) Download test blend file [scenes.blend](https://archive.blender.org/developer/F8060688/scenes.blend)
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: 
```Scene.005
Scene.005
Scene.005
Scene.005
Scene.005
Scene.005

Scene
Scene.001
Scene.002
Scene.003
Scene.004
Scene.005```
**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 print(context.scene.name)``` ``` **Exact steps for others to reproduce the error** 1 ) Download test blend file [scenes.blend](https://archive.blender.org/developer/F8060688/scenes.blend) 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: ```Scene.005 Scene.005 Scene.005 Scene.005 Scene.005 Scene.005 Scene Scene.001 Scene.002 Scene.003 Scene.004 Scene.005```
Author

Added subscriber: @mikewazowski11

Added subscriber: @mikewazowski11

Added subscriber: @lemenicier_julien

Added subscriber: @lemenicier_julien

Added subscriber: @mont29

Added subscriber: @mont29

Changed status from 'Open' to: 'Archived'

Changed status from 'Open' to: 'Archived'
Bastien Montagne self-assigned this 2019-11-15 17:25:54 +01:00

Yep, you need to ensure update is effective then, see https://docs.blender.org/api/current/info_gotcha.html#stale-data

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

Yep, you need to ensure update is effective then, see https://docs.blender.org/api/current/info_gotcha.html#stale-data We do not handle user support on this tracker, only bug reports. User forums like [blenderartists.org](http:*blenderartists.org/) or [blender.stackexchange.com](http:*blender.stackexchange.com/) and our [devtalk](https://devtalk.blender.org) should be used for that matter.
Author

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

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

@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.

@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.

Changed status from 'Archived' to: 'Open'

Changed status from 'Archived' to: 'Open'

Added subscriber: @ideasman42

Added subscriber: @ideasman42

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).

@ideasman42 would not consider this a bug, more like some internal limitation?

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). @ideasman42 would not consider this a bug, more like some internal limitation?
Author

@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 https://docs.blender.org/api/current/info_gotcha.html#can-i-redraw-during-the-script hack?

@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 https://docs.blender.org/api/current/info_gotcha.html#can-i-redraw-during-the-script 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…

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…
Bastien Montagne was unassigned by Dalai Felinto 2019-12-23 13:43:55 +01:00
Member

Added subscriber: @Jeroen-Bakker

Added subscriber: @Jeroen-Bakker
Member

Changed status from 'Confirmed' to: 'Archived'

Changed status from 'Confirmed' to: 'Archived'
Jeroen Bakker self-assigned this 2020-01-13 16:37:18 +01:00
Member

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

This issue seems like a feature request. The system works as intended, but there are limitations what needs development.
Sign in to join this conversation.
No Milestone
No project
No Assignees
4 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#71542
No description provided.