Update custom fields when publishing

Hi there,
I want to update some fields I created whenever I publish a version.

With the help provided in this post, I modified publish_file.py to add some keys and values to publish_data dictionnary before sgtk.util.register_publish is called. All keys are created fields that I checked exist on Shotgun Version.

  • I also dump publish_data in a last_publish_datas.json file in the Logs folder to check everything is okay.
    The dict in the json has my modifications, but the new fields on the uploaded Version on website Shotgun does not seem to be modified during the publish.

  • I did not override before_register_publish (doc page warn us about that).

  • Usual fields are setuped just like a non customized publish (‘created_by’ has the correct infos, for exemple)

  • tk-multi-publish.yml loads "{config}/publish_file.py" (otherwise the jsonwould not be created)

Simplified exemple of my publish_file modifications:

def addToPublishData(self, publish_data):
    sg_extension = os.path.splitext(publish_path)[1]
    publish_data['sg_extension']                    =  sg_extension

    return publish_path

…

self.logger.info("Registering publish...")
publish_data = {
            "tk": publisher.sgtk, ............ }


self.addToPublishData(publish_data)

# add extra kwargs
publish_data.update(publish_kwargs)

self.dumpJson(publish_data)

# log the publish data for debugging
self.logger.debug(
        "Populated Publish data...",
            extra={.................... })

item.properties.sg_publish_data = sgtk.util.register_publish(**publish_data)

Do you have any idea why my fields are not updated?

Thanks

PS: where are the publish_file logg outputed? I can’t find any instance of ‘Populated Publish data…’ in any local log file.

2 Likes

Hey! I think there might be some confusion between Version and PublishedFile entities going on here. The sgtk.util.register_publish, method will create a PublishedFile entity, and you can provide custom field values for that entity through the register method via the sg_fields kwarg.
However, since the method doesn’t create Version entities, I think you may be looking in the wrong place?
Is it definitely Version entities you want or are you referring to publishes as versions?

It’s not output, unfortunately. We have a ticket logged internally to change this behavior.
You can copy it from the app window however, there is a dedicated button.

2 Likes

Hi Philip,
There may be some confusion here, indeed :smiley:

I want to customize the files infos that are uploaded to Shotgun and can be found in the Media Page or in the “Versions” page of an asset.

For instance, when we publish a psd using Shotgun Adobe Pannel, or when we publish a font file through the Publisher App.

2 Likes

OK, great thanks for clarifying.
What you are seeing on on the “Versions” page are Version entities. Version entities are created by the publisher when there is some reviewable media to upload such as an image or video. These are different from the PublishedFile entities that represent the files you are working on in Toolkit.

By default, the publish app will always create PublishedFile entities (via the sgtk.util.register_publish method) but will only additionally create Version entities if there is something that can be uploaded to Shotgun and reviewed.

See this doc for more details on the differences between publishes and versions.

For changing the Version field data, the upload_version.py hook is what you will need to modify.

3 Likes

Thanks for the clarification!

1 Like

In files files like tk-multi-publish2.yml, path starting with {self} are descripted as:
{self}/path/to/foo.py – looks in the hooks folder in the local app, engine of framework.

If I understand correctly, {self} will look in /install/app_store folder, then check for the file in engine if it fails ? What is the use of {self} ?

Why is the file loaded twice in this yml for several DCC, once from {self} and once from {engine}?

settings.tk-multi-publish2.photoshop.asset_step:
...
  - name: Upload for review
    hook: "{self}/upload_version.py"
    settings: {}
...
  - name: Upload for review
    hook: "{engine}/tk-multi-publish2/basic/upload_version.py"

Thanks

2 Likes

No {self} will only look in the local folder for the app, engine or framework. So in this case, as the hook is for the tk-multi-publish2 app, it will look within that app’s bundle. It won’t also check the engine.
You can read more about what those tokens do here (you need to scroll down a short way).

You can introduce inheritance using : which is also discussed in these two posts:

Inheritance would allow you to have that fallback behavior so that if a method wasn’t defined in the engine hook, it could look in the app’s hook, (normal python inheritance behavior.)

That’s a really good question and I can see why it looks like it is the same thing loading twice but, despite the name, they are being treated as two separate plugins. The key is to look at what collected items they act on.

{self}/upload_version.py - This is the upload_version plugin that comes with the publish2 app, so it is not specific to any engine in particular. It is designed to handle specifically "file.image" and "file.video" collected items.

{engine}/tk-multi-publish2/basic/upload_version.py - This plugin comes from the tk-photoshopcc engine and as such can be written in a way that is specific to Photoshop. It responds to "photoshop.document" type collected items.

So by having both of these plugins registered as separate plugins rather than inheriting from each other, they are able to handle different collected items separately.

3 Likes

Okay, thanks a lot for the help!

3 Likes