Skip to content

Integrator: Refactor to ContextPlugin and add type hints - #1992

Open
BigRoy wants to merge 13 commits into
developfrom
enhancement/integrate_ContextPlugin
Open

BigRoy wants to merge 13 commits into
developfrom
enhancement/integrate_ContextPlugin

Conversation

@BigRoy

@BigRoy BigRoy commented Aug 7, 2026

Copy link
Copy Markdown
Member

Changelog Description

Integrator: Refactor to ContextPlugin and add type hints

Additional info

Turning this into an integrator allows us to optimize some queries, like the prefetching of products, version data, etc. and also join the file transactions into one threaded bulk and the OperationsSession into fewer bulks. This should make big ingests with many instances faster. But timings will still need to be made.

Draft for now, because it needs more performance tests but also general discussion

Testing notes:

  1. Publishing should work from all DCCs

@BigRoy
BigRoy requested review from antirotor and iLLiCiTiT August 7, 2026 19:05
@BigRoy BigRoy self-assigned this Aug 7, 2026
@BigRoy BigRoy added the type: enhancement Improvement of existing functionality or minor addition label Aug 7, 2026
@ynbot ynbot added the size/M label Aug 7, 2026
@BigRoy
BigRoy requested a lite review from Copilot August 10, 2026 08:05
@BigRoy

BigRoy commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

@iLLiCiTiT can you give me your thoughts on this?

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

Refactors the publish integrator to operate as a pyblish.api.ContextPlugin with more upfront data prefetching (products/versions/representations) and introduces stronger typing via dataclasses and type hints to support faster large ingests.

Changes:

  • Converted IntegrateAsset from InstancePlugin to ContextPlugin and integrated all eligible instances in one pass.
  • Added _PreparedInstance / _PreparedRepresentation dataclasses and expanded type hints across the integrator code.
  • Added operation chunking (operations_chunk_size) and prefetch logic via get_products / get_versions / get_representations.
Suppressed comments (2)

client/ayon_core/plugins/publish/integrate.py:915

  • Using assert here is unsafe because asserts can be stripped with -O, and then repre_context["frame"] = ... could crash if repre_context is unexpectedly None. Prefer an explicit guard (and keep the final if repre_context is None: raise as the authoritative error).
            if not is_udim:
                assert repre_context is not None
                repre_context["frame"] = first_index_padded

client/ayon_core/plugins/publish/integrate.py:920

  • This assert can be stripped with -O, so the next line could crash if repre_context is None. Use a guard instead of an assert for safety.
            if instance.data.get("renderlayer"):
                assert repre_context is not None
                repre_context["renderlayer"] = instance.data["renderlayer"]

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

Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
Comment thread client/ayon_core/plugins/publish/integrate.py
Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
@ynbot ynbot moved this to Review In Progress in PR reviewing Aug 10, 2026
Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
BigRoy and others added 4 commits August 10, 2026 14:11
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@BigRoy
BigRoy requested a review from iLLiCiTiT August 13, 2026 18:55
@BigRoy
BigRoy marked this pull request as ready for review August 21, 2026 11:46
@BigRoy
BigRoy requested a review from jakubjezek001 August 21, 2026 11:47
@BigRoy

BigRoy commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

May be good to do some performance testing with this. Maybe @antirotor loves to do that, or @jakubjezek001 comparing it with latest develop on a large CSV ingest or alike? :)

@moonyuet

Copy link
Copy Markdown
Member

I agree that we need to do some performance testing and my concern is whether prefetching data in this PR rapidly increasing memory usage.

  1. Multiple instances
  2. Single very large dataset (CSV ingest etc.)
  3. Extremely large instance count

import logging
import sys
import copy
from dataclasses import dataclass

@iLLiCiTiT iLLiCiTiT Sep 15, 2026

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.

Dataclasses can't be used. Same issue as here #2050

@BigRoy BigRoy Sep 15, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

They can, if you don't have from __future__ import annotations in the file. ;)
As such, do we still care?

Also, given how painful this is it makes me wonder if we should have a dataclass decorator wrapper that avoids the bug, just so we can use dataclasses. Because this stuff gets painful easily otherwise.

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 have it in my TODO list to fix the issue.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's fixed in pyblish pyblish/pyblish-base#403 btw ;) there's just no new pyblish release since.

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.

BTW I think from __future__ import annotations is issue with core's import logic, but with pyblish import logic it fails completelly event without the import.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Pretty sure the pyblish one also ONLY happened if that from future import was there. @antirotor worked on that fix at the time.

@iLLiCiTiT iLLiCiTiT Sep 15, 2026

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.

Added PR #2062 to fix the dataclasses issue.

@iLLiCiTiT iLLiCiTiT Sep 15, 2026

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.

Pretty sure the pyblish one also ONLY happened if that from future import was there. @antirotor worked on that fix at the time.

Oh, yeah, but that is not released, and 100% is not in any dependency package we have. So in practice we can't rely on it.

Comment thread client/ayon_core/plugins/publish/integrate.py
Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
template_data["udim"] = index
else:
template_data["frame"] = index
template_filled = path_template_obj.format_strict(

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.

NOTE: In ideal case scenario we should collect file info now. The template_filled object has rootless path with root that was 100% used instead of guessing it later on.

"anatomy_data": template_data,
"transfers": transfers,
return _PreparedRepresentation(
representation=repre_doc,

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.

Why the hell is the variable still named repre_doc? 😆

Comment thread client/ayon_core/plugins/publish/integrate.py Outdated
BigRoy and others added 4 commits September 15, 2026 14:01
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M type: enhancement Improvement of existing functionality or minor addition

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

5 participants