pyblish / pyblish-base

Pyblish base library - see https://github.com/pyblish/pyblish for details.
Other
127 stars 59 forks source link

Actions don't work with explicit plug-ins #254

Closed mottosso closed 8 years ago

mottosso commented 8 years ago

Actions paired to InstancePlugin throws an AssertionError.

# Traceback (most recent call last):
#   File "P:\pipeline\dev\git\pyblish-win\lib\pyblish\modules\pyblish-rpc\pyblish_rpc\service.py", line 119, in _dispatch
#     return func(*params)
#   File "P:\pipeline\dev\git\pyblish-win\lib\pyblish\modules\pyblish-rpc\pyblish_rpc\service.py", line 97, in process
#     action=action)
#   File "P:\pipeline\dev\git\pyblish-win\lib\pyblish\modules\pyblish-base\pyblish\plugin.py", line 414, in process
#     return __explicit_process(plugin, context, instance, action)
#   File "P:\pipeline\dev\git\pyblish-win\lib\pyblish\modules\pyblish-base\pyblish\plugin.py", line 430, in __explicit_process
#     "Cannot process an InstancePlugin without an instance. This is a bug")
# AssertionError: Cannot process an InstancePlugin without an instance. This is a bug

The error lies in a logic check made here:

Which is logically making sure that, if a plug-in is an InstancePlugin but there is no instance being passed, the caller of this function is doing something wrong. But what it doesn't to take into account, is if there is an Action being processed, there doesn't have to be an instance.

Thanks to @madoodia and @BigRoy for spotting this.

mottosso commented 8 years ago

To reproduce:

import pyblish.api
import pyblish.plugin

class MyAction(pyblish.api.Action):
    def process(self, plugin, context):
        assert False, "Action ran"

class MyValidator(pyblish.api.InstancePlugin):
    order = pyblish.api.ValidatorOrder

    actions = [
        pyblish.api.Category("Scene"),
        MyAction,
    ]

context = pyblish.api.Context()
result = pyblish.plugin.process(MyValidator, context, instance=None, action="MyAction")
assert str(result["error"]) == "Action ran"