Page MenuHome

Function from Python not being loaded for Driver when project opened
Closed, ResolvedPublic

Description

System Information
Operating system: Pop!_OS (Debian) 18.10
Graphics card: GTX Titan X

Blender Version
Broken:
2.80 77eaa4790d37
Worked: (optional)

A driver calls on a python function. The python function is internal and registered.

When the project is opened, the driver can't find the function, throwing up "ERROR: Invalid Python expression".

Pressing "Update Dependencies" fixes the problem

Exact steps for others to reproduce the error
With 'driver-bug-test.blend':

  • Open the project.
  • Enter pose mode for the armature
  • Try moving it along the X axis (Moving the armature along the x axis should make the cube move along the Y-axis, but it doesn't)
  • Exit pose mode
  • Select the cube
  • In the Drivers panel, you'll see in the Driver Property panel an error "ERROR: Invalid Python expression"
  • Clicking 'Update Dependencies' allows the driver to start working correctly.

This happens each time the project is opened.

I'd be happy to just click this button each time I load, but if you have a project with many items being driven by functions, it's not practical at all.

Event Timeline

Brecht Van Lommel (brecht) triaged this task as Confirmed, Medium priority.

@Sergey Sharybin (sergey), this traces back to rBd192d723123a: Ensure dependency graph exists before initializing editors.

Python module registration should be done before the depsgraph like in 2.7 I think, for cases like this. Wouldn't mind an extra pair of eyes to check if it's safe though.

diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index 120bf65..5295064 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -491,12 +491,6 @@ static void wm_file_read_post(
 
        CTX_wm_window_set(C, wm->windows.first);
 
-       Main *bmain = CTX_data_main(C);
-       DEG_on_visible_update(bmain, true);
-       wm_event_do_depsgraph(C);
-
-       ED_editors_init(C);
-
 #ifdef WITH_PYTHON
        if (is_startup_file) {
                /* possible python hasn't been initialized */
@@ -526,6 +520,12 @@ static void wm_file_read_post(
        UNUSED_VARS(is_startup_file, reset_app_template);
 #endif  /* WITH_PYTHON */
 
+       Main *bmain = CTX_data_main(C);
+       DEG_on_visible_update(bmain, true);
+       wm_event_do_depsgraph(C);
+
+       ED_editors_init(C);
+
        WM_operatortype_last_properties_clear_all();
 
        /* important to do before NULL'ing the context */