Some Blender operators can only be called from the workspace for which they are intended.
If you call from the Python console, for example, an operator intended only for working in the 3D Viewport area, the operator will not be executed:
or it will fail with an error message about the incorrect context:
# RuntimeError: Operator bpy.ops.view3d.background_image_add.poll() failed, context is incorrect
However, we can still execute operators from a non-native working area. To do this, we can pass the first implicit parameter to any operator – a pointer to the context of the area in which this operator should be executed. This parameter commonly named the “overridden context”.
This method is suitable for Blender version 3.1 and earlier. For Blender 3.2 and later, we must use the temp_override() method.
Context overrideRead More »