Repair run on valid assets


#1

Got a plugin that repairs some assets, but it seems to repair both valid and failed assets.

Is that expected behaviour?


#2

Sounds like a bug.

If you can create something short to reproduce, I’ll have a look at this asap.

Edit: As a temporary workaround, in your repair method, you could look up the currently running instance from the results dictionary of the Context, and see whether it has any failures. If it doesn’t, you could return early.


#3

Scene creation:

import pymel

for count in range(0, 7):
    pymel.core.spaceLocator()

Collector:

import pyblish.api
import pymel


class CollectLocators(pyblish.api.Collector):
    """
    """

    def process(self, context):

        for node in pymel.core.ls(type='locator'):
            instance = context.create_instance(name=node.name())
            instance.set_data('family', value='locators')
            instance.add(node.getParent())

Validator:

import random

import pyblish.api
import pymel


class ValidateLocators(pyblish.api.Validator):
    """
    """

    families = ['locators']

    def process(self, instance):

        assert bool(random.getrandbits(1)), 'Something is wrong with this.'

    def repair(self, instance):

        self.log.info('This asset failed validation: %s' % instance)

#4

Thanks, I found the problem. It’ll be fixed in the next release for tomorrow.


#5

Fixed in the latest Pyblish QML 0.3.1

It’s been included in Pyblish for Windows 1.1.1.


#6

Did this work out for you @tokejepsen?


#7

Haven’t tried it out yet. On my list of things to do:)


#8

Ok, no problem. :slight_smile:


#9

Its working:) Small note though, is that the failed assets don’t turn green when repairing. Pretty sure they used to do that, but no biggie if not.

Also for future reference, I always forget that you can register plugins, so the code example is better like this;

import random

import pyblish.api
import pymel


for count in range(0, 7):
    pymel.core.spaceLocator()

class CollectLocators(pyblish.api.Collector):
    """
    """

    def process(self, context):

        for node in pymel.core.ls(type='locator'):
            instance = context.create_instance(name=node.name())
            instance.set_data('family', value='locators')
            instance.add(node.getParent())

class ValidateLocators(pyblish.api.Validator):
    """
    """

    families = ['locators']

    def process(self, instance):

        assert bool(random.getrandbits(1)), 'Something is wrong with this.'

    def repair(self, instance):

        self.log.info('This asset failed validation: %s' % instance)

pyblish.api.register_plugin(CollectLocators)
pyblish.api.register_plugin(ValidateLocators)