Page MenuHome

python unreliable result for when used in drivers
Confirmed, NormalPublic


System Information
Operating system: Linux-4.15.0-96-generic-x86_64-with-debian-buster-sid 64 Bits
Graphics card: GeForce GTX 980/PCIe/SSE2 NVIDIA Corporation 4.5.0 NVIDIA 430.50

Blender Version
Broken: version: 2.82 (sub 7), branch: master, commit date: 2020-03-12 05:06, hash: rB375c7dc4caf4
Worked: Never (2.8+)

Short description of error
python gives unreliable results for when used in drivers

Exact steps for others to reproduce the error
1 Run the text script to record the python method isViewLayer1 for drivers
2 Edit the driver for the custum property "prop" in the scene panel (bottom right) -> shows invalid python expression (weird but not the core of the problem)
3 Press "update dependencies" -> gives result 1 as expected
4 Switch to "View Layer2" -> gives result 0 or 1 at random
5 Press "update dependencies" mulptiple time -> gives result 0 or 1 at random

For reference, this is the script:

import bpy
from import persistent
from import driver_namespace
print (

def isViewLayer1():
    if "View Layer 1" in
        return 1
        return 0

def load_handler(dummy):
    print("Load Handler")
    #dns =
    # register your drivers['isViewLayer1'] = isViewLayer1

def register():


Event Timeline

Richard Antalik (ISS) changed the task status from Needs Triage to Confirmed.Apr 14 2020, 12:58 PM
Richard Antalik (ISS) updated the task description. (Show Details)

Accessing bpy.context from within a driver function is problematic, as it's unaware of which context is actually active at the time. For example, Blender could be rendering one view layer while displaying a different one in the 3D viewport.

Evaluating bpy.context.view_layer depends on the current window to obtain the current view layer, so it will fail (by returning the default view layer) when there is no window. Why this happens seemingly randomly when updating the relations is still unknown to me.

The underlying issue is that the driver functions don't have access to the dependency graph. I have written T77086: Passing Dependency Graph to Drivers for this.