mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-24 21:04:40 +01:00
Do not create a new instance, just update the existing instance
This commit is contained in:
parent
5ad7103f57
commit
129d5d6b0e
2 changed files with 4 additions and 43 deletions
|
|
@ -12,7 +12,6 @@ import six
|
|||
import pyblish.api
|
||||
|
||||
from .publish_plugins import AbstractMetaContextPlugin
|
||||
from .lib import replace_instance_in_context
|
||||
|
||||
|
||||
@attr.s
|
||||
|
|
@ -218,16 +217,10 @@ class AbstractCollectRender(pyblish.api.ContextPlugin):
|
|||
data = self.add_additional_data(data)
|
||||
render_instance_dict = attr.asdict(render_instance)
|
||||
|
||||
instance = context.create_instance(render_instance.name)
|
||||
if render_instance.source_instance is not None:
|
||||
# remove the new instance, because we want to insert it
|
||||
# at the position of the original instance to replace the
|
||||
# source instance in the context completely
|
||||
context.pop()
|
||||
replace_instance_in_context(
|
||||
context,
|
||||
source_instance=render_instance.source_instance,
|
||||
destination_instance=instance)
|
||||
instance = render_instance.source_instance
|
||||
else:
|
||||
instance = context.create_instance(render_instance.name)
|
||||
|
||||
instance.data.update(render_instance_dict)
|
||||
instance.data.update(data)
|
||||
|
|
|
|||
|
|
@ -933,36 +933,4 @@ def get_publish_instance_families(instance):
|
|||
output.append(family)
|
||||
families.discard(family)
|
||||
output.extend(families)
|
||||
return output
|
||||
|
||||
|
||||
def replace_instance_in_context(
|
||||
context: pyblish.api.Context,
|
||||
source_instance: pyblish.api.Instance,
|
||||
destination_instance: pyblish.api.Instance
|
||||
):
|
||||
"""Replace source instance with the destination instance.
|
||||
|
||||
This transfers the instance's IDs so that the new instance acts exactly
|
||||
as if it was the source instance the whole time. This is required for
|
||||
the publisher to correctly detect and transfer the logs relevant for the
|
||||
instance.
|
||||
|
||||
"""
|
||||
# Transfer the pyblish.api.Instance id
|
||||
destination_instance._id = source_instance.id
|
||||
|
||||
# Transfer the `instance_id` of the new publisher's instances
|
||||
key = "instance_id"
|
||||
if key in source_instance.data:
|
||||
destination_instance.data[key] = source_instance.data[key]
|
||||
|
||||
# Replace the instance at the same index in the context
|
||||
for idx, instance in enumerate(context):
|
||||
if source_instance is instance:
|
||||
context[idx] = destination_instance
|
||||
return
|
||||
|
||||
raise ValueError(
|
||||
f"Source instance {source_instance} not found in context."
|
||||
)
|
||||
return output
|
||||
Loading…
Add table
Add a link
Reference in a new issue