with context.temp_override(area=context.area)
doesn't restore original area
or region
after with
scope. #110632
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#110632
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
System Information
Operating system: Linux-5.4.0-149-generic-x86_64-with-glibc2.31 64 Bits, X11 UI
Graphics card: NVIDIA GeForce RTX 3080 Ti/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 525.116.04
Blender Version
Broken: version: 3.6.0, branch: blender-v3.6-release, commit date: 2023-06-27 08:08, hash:
c7fc78b81ecb
Short description of error
The context-manager from
context.temp_override
doesn't restore the originalarea
orregion
objects when those are the current ones in context. As result, the original context is invalidated. This doesn't happen for all kinds of data matching the original context, for example, the currentwindow
is correctly restored, and other data such asscreen
,space_data
oractive_object
seems to be unaffected by this.Exact steps for others to reproduce the error
Here's a code snippet to try this out.
Run this in the Text editor and then call the operator from the 3D View with F3 > test.test
When calling the operator, we get
if the script was written in this way:
Then the output is expected:
The area gets invalidated, so from now on all script attempts to use
context.area
in the same invoke scope will fail.As you can see, we are overriding the original context with its own data, which is the only exception to use temp_override. If we pass data which is different than the current context, everything's restored properly.
temp_override
should restore or just plain ignore the overridden element when it matches the current one in context. This allows to programatically pass overrides without having to worry or check if the overridden data is part of the current context. This way, things likeif area_override == context.area: # avoid calling temp_override
can be safely ignored.context.window
works ok, whilecontext.area
andcontext.region
don't.context.temp_override doesn't restore 'area' or 'region' when provided with its own contextto `with context.temp_override(area=context.area) doesn't restore 'area' or 'region' after `with` scope.`with context.temp_override(area=context.area) doesn't restore 'area' or 'region' after `with` scope.to `with context.temp_override(area=context.area)` doesn't restore original `area` or `region` after `with` scope.I don't know python that well to see if the
with
keyword is behaving as expected, but it feels like a bug to me.@ChengduLittleA Sorry if I sound rude, but in my opinion, if you weren't sure about what the
with
statement does, you shouldn't have edited the report that way.This part of the code doesn't make sense, since this way you are not really making use of the context-manager.
temp_override
returns the context-manager object containing the__enter__
and__exit__
methods which are automatically called by thewith
statement to open and close a certain context throughout the duration of thewith
scope.This is certainly not a problem about the
with
statement, which is being used canonically here.The problem relies on what the context-manager object does on
__exit__
Here's an example showing the same symptom without having to use the
with
statement. We get the same problem as before.I see... Then the problem is now apparent, that
__exit__()
somehow did not run or failed to do the job. Thanks for clarifying!