Skip to content

Add check_inventory_version in create and load callback function - #353

Open
moonyuet wants to merge 12 commits into
developfrom
bugfix/352-check_inventory_versions-should-be-called-on-workfile-load-(via-workfiles-app)
Open

Add check_inventory_version in create and load callback function#353
moonyuet wants to merge 12 commits into
developfrom
bugfix/352-check_inventory_versions-should-be-called-on-workfile-load-(via-workfiles-app)

Conversation

@moonyuet

@moonyuet moonyuet commented Aug 19, 2026

Copy link
Copy Markdown
Member

Changelog Description

This PR is to add check_inventory_version in create and load callback function to ensure the check_inventory_version would apply when the nuke session is opened via workfile tools.

Additional review information

Fix #352

Testing notes:

  1. Launch Nuke
  2. Load something with not the latest version
  3. Save your scene via workfile tools(SceneA)
  4. Updated to the latest version to your loaded asset
  5. Save your scene via workfile tools (SceneB)
  6. Open your Scene A back via workfile tools
  7. It should be showing the correct color.

@moonyuet moonyuet self-assigned this Aug 19, 2026
@moonyuet moonyuet added the type: bug Something isn't working label Aug 19, 2026

@BigRoy BigRoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand the reasoning here, but I think it's the wrong fix. I wouldn't expect on_script_create to get called when opening a file.

I think the reason why the nuke load event does not trigger and hence on_script_load does not trigger is because of how we open the file here:

nuke.scriptReadFile(nuke_script)

Essentially, we're not opening a new script - but we're reading it - which is a workaround we have to avoid Nuke opening a new window. Which makes me think we should enforce, from that open logic to trigger the load callback manually then.

So that whenever we do a load, we still expect the load callback to be triggerered.

Looking at that logic it only applies if not ASSIST so it may need to be at the end of that if with some comment as to why we need to trigger the event ourselves.

I'd actually almost go as far as to just put a call to nuke.onScriptLoad() there.

So, confirm this is indeed the case, and if so - add the dedicated call to nuke.onScriptLoad() to enforce it.

@moonyuet
moonyuet requested a review from BigRoy August 19, 2026 15:00
@BigRoy

BigRoy commented Aug 19, 2026

Copy link
Copy Markdown
Member

@moonyuet I noticed you already re-requested review, but this wasn't added yet - right?

I'd actually almost go as far as to just put a call to nuke.onScriptLoad() there.

@moonyuet

moonyuet commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

@moonyuet I noticed you already re-requested review, but this wasn't added yet - right?

I'd actually almost go as far as to just put a call to nuke.onScriptLoad() there.

so we dont need this PR basically, right?

If you talk about adding the script load callback in the open workfile, we might need to find if there is some alternatives for that like the callback for workfile

…d-be-called-on-workfile-load-(via-workfiles-app)
@sebastianbrandhuber

Copy link
Copy Markdown
Contributor

@moonyuet @BigRoy
Just saw the discussion here.
What about we manually trigger all existing onScriptLoad callbacks right after here?

nuke.scriptReadFile(nuke_script)

Something like

callbacks = [tup[0] for cb_list in nuke.onScriptLoads.values() for tup in cb_list]
for func in callbacks:
    if callable(func):
        func()

should do the trick.

The problem is, that nuke.addOnCreate callbacks will be executed aswell and most likely execute some functions twice.
We might need to clear nuke.onCreates before executing the code and restore it afterwards, but I did not test that part.

BigRoy added 3 commits August 20, 2026 00:40
…-workfile-load-(via-workfiles-app)' of https://github.com/ynput/ayon-nuke into bugfix/352-check_inventory_versions-should-be-called-on-workfile-load-(via-workfiles-app)
@BigRoy

BigRoy commented Aug 19, 2026

Copy link
Copy Markdown
Member

What about we manually trigger all existing onScriptLoad callbacks right after here?

No need, you can just call nuke.onScriptLoad() ;)

The problem is, that nuke.addOnCreate callbacks will be executed aswell and most likely execute some functions twice.
We might need to clear nuke.onCreates before executing the code and restore it afterwards, but I did not test that part.

I think we shouldn't actually. I think we should make our "open file" behavior mimic as if the user would do File > Open manually as much as possible. it seems like, if the user does that - it also triggers both the on create root callback and the script open callback.

The assumption that on create would only happen on "new" files and not on scene open then maybe is wrong.

I've now pushed two commits that should make it behave as we'd expect.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to ensure check_inventory_versions is applied when a Nuke workfile is opened via the Workfiles tools within an existing Nuke session (matching issue #352), so container “version state” coloring stays correct on workfile loads that bypass Nuke’s usual script-open flow.

Changes:

  • Manually triggers “script load” handling after loading a script via scriptClear() + scriptReadFile() in workio.open_file.
  • Moves check_inventory_versions() execution into the on_script_load callback (instead of registering it as a separate addOnScriptLoad callback).
  • Adjusts on_root_create behavior to try to only apply “new scene creation” settings when no current file is set.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
client/ayon_nuke/api/workio.py Attempts to manually trigger script-load behavior after scriptReadFile so workfile-open flow runs expected callbacks.
client/ayon_nuke/api/pipeline.py Consolidates inventory version checking into on_script_load and refines on_root_create logic for new-scene-only settings.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread client/ayon_nuke/api/workio.py Outdated
Comment thread client/ayon_nuke/api/pipeline.py
@BigRoy

BigRoy commented Aug 20, 2026

Copy link
Copy Markdown
Member

I pushed some tweaks @moonyuet.

Essentially now it should behave similar to regular file open as to the callbacks that get called.

  • It doesn't trigger the onCreate callback anymore before file open, only after it's been opened.
  • It also triggers the onScriptLoad callback now.
  • I've also changed the autosave prompt logic - previously it first opened the file, then asked to open the autosave, and then opened the autosave. Essentially meaning it'd open the file twice if you clicked yes - now it'll give the prompt before opening the file, and hence open only once.
  • I believe this now also doesn't trigger the empty scene on create logic before the file is opened when opening a file on launch, so it doesn't run logic potentially twice that would've been discarded due to the scene file being opened anyway.

Things to test would be:

  • Workfile template builder still runs when it should be running.
  • callbacks trigger on the right moments.
  • callbacks should not be running multiple times unnecessarily if nuke would usually not do that either on e.g. file open (like on startup or autosave as described above)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check_inventory_versions should be called on workfile load (via workfiles app)

5 participants