Skip to content

validate_version

ValidateVersion

Bases: InstancePlugin, OptionalPyblishPluginMixin

Validate instance version.

AYON does not allow overwriting previously published versions.

Source code in client/ayon_core/plugins/publish/validate_version.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
class ValidateVersion(pyblish.api.InstancePlugin, OptionalPyblishPluginMixin):
    """Validate instance version.

    AYON does not allow overwriting previously published versions.
    """

    order = pyblish.api.ValidatorOrder

    label = "Validate Version"

    optional = False
    active = True

    @classmethod
    def apply_settings(cls, settings):
        # Disable if no profile is found for the current host
        profiles = (
            settings
            ["core"]
            ["publish"]
            ["ValidateVersion"]
            ["plugin_state_profiles"]
        )
        profile = filter_profiles(
            profiles, {"host_names": get_current_host_name()}
        )
        if not profile:
            cls.enabled = False
            return

        # Apply settings from profile
        for attr_name in {
            "enabled",
            "optional",
            "active",
        }:
            setattr(cls, attr_name, profile[attr_name])

    def process(self, instance):
        if not self.is_active(instance.data):
            return

        version = instance.data.get("version")
        latest_version = instance.data.get("latestVersion")

        if latest_version is not None and int(version) <= int(latest_version):
            # TODO: Remove full non-html version upon drop of old publisher
            msg = (
                "Version '{0}' from instance '{1}' that you are "
                "trying to publish is lower or equal to an existing version "
                "in the database. Version in database: '{2}'."
                "Please version up your workfile to a higher version number "
                "than: '{2}'."
            ).format(version, instance.data["name"], latest_version)

            msg_html = (
                "Version <b>{0}</b> from instance <b>{1}</b> that you are "
                "trying to publish is lower or equal to an existing version "
                "in the database. Version in database: <b>{2}</b>.<br><br>"
                "Please version up your workfile to a higher version number "
                "than: <b>{2}</b>."
            ).format(version, instance.data["name"], latest_version)
            raise PublishValidationError(
                title="Higher version of publish already exists",
                message=msg,
                description=msg_html
            )