Skip to content

fix(skills): re-register driver functions on file load - #411

Merged
TMHSDigital merged 1 commit into
mainfrom
fix/driver-namespace-load-post
Oct 5, 2026
Merged

TMHSDigital merged 1 commit into
mainfrom
fix/driver-namespace-load-post

Conversation

@TMHSDigital

Copy link
Copy Markdown
Owner

Closes #387.

Problem

bpy.app.driver_namespace is reset on every file load. The skill and snippets/driver-with-custom-function.py registered the custom function only in register(). On the first file a user opens:

  • the driver evaluates with the function missing;
  • it raises NameError and is disabled (driver.is_valid = False);
  • it stays disabled even after the function is re-added.

Change

  • Snippet:
    • restore_driver_function(), a @persistent load_post handler, re-registers the function and resets is_valid on drivers on objects, shape keys and materials;
    • symmetric register()/unregister();
    • the header explains the reset.
  • Skill:
    • the same pattern, plus a note to extend the ID collections;
    • the compatibility table row now says "reset on file load";
    • a new common-mistakes entry.

Evidence

Proven by live run (--factory-startup; binaries report 5.2.1 LTS and 4.5.11 LTS). The probe imports the real snippet, attaches its smoothstep driver, evaluates at frame 50, then does save_as_mainfile → open_mainfile → re-evaluates:

Mode 5.2.1 z after reopen / is_valid 4.5.11
New register() (with load_post handler) 2.4621 / True 2.4621 / True
Old pattern (register only) 0.0 / False, NameError 0.0 / False
Old pattern + function re-added after load, no is_valid reset 0.0 / False 0.0 / False

Before the save, z = 2.4621 in every mode. The last row shows why the is_valid reset is required, not just the re-registration.

By inspection only: the snippet is 61 lines (limit 75).

🤖 Generated with Claude Code

driver_namespace is reset on every file load. The skill and snippet
registered the function only in register(), so the first file a user
opens evaluates the driver without it: NameError, the driver is disabled
(is_valid False), and it stays disabled even after the function is put
back. Measured on 4.5.11 and 5.2.1: z went from 2.4621 to 0.0 across a
save and reopen.

Both now re-register from a @Persistent load_post handler that also
resets driver.is_valid, with symmetric register/unregister. The skill's
compatibility table and common-mistakes list say why.

Closes #387

Signed-off-by: TMHSDigital <154358121+TMHSDigital@users.noreply.github.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@TMHSDigital

Copy link
Copy Markdown
Owner Author

CI evidence before merge: all checks pass ( 13 pass ). Blender Smoke on PR head: Blender 5.2.2 LTS / Blender 4.5.14 LTS. Summaries (happy path; falsifiers) per leg: 141 passed, 3 skipped, 0 failed;136 passed, 6 skipped, 0 failed;143 passed, 1 skipped, 0 failed;142 passed, 0 skipped, 0 failed;

@TMHSDigital
TMHSDigital merged commit e1d8310 into main Oct 5, 2026
13 checks passed
@TMHSDigital
TMHSDigital deleted the fix/driver-namespace-load-post branch October 5, 2026 00:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

skills: driver_namespace functions registered only in register() vanish on file load, and the driver stays dead

1 participant