senaite.core icon indicating copy to clipboard operation
senaite.core copied to clipboard

Issue with wildcards in calculations.

Open RML-IAEA opened this issue 2 years ago • 0 comments

Description

Issue with wildcards in calculations. see error: "Wildcards for interims are not allowed:" image In the current code wildcards cannot be used without defining the keyword elsewhere in the function. You cannot use the "keyword.wildcard" by itself.

Reproduction guide

Create the analysis service "gs_Be7_00 " and calculation "send_object" and attempt to run it. gs_Be7_00 is a keyword for the analysis service

Looking at the code:

        keywords = re.compile(r"\[([^\.^\]]+)\]").findall(value)
        for keyword in keywords:
            # Check if the service keyword exists and is active.
            dep_service = catalog(getKeyword=keyword, is_active=True)
            if not dep_service and keyword not in interim_keywords:
                msg = _(
                    "Validation failed: Keyword '${keyword}' is invalid",
                    mapping={
                        'keyword': safe_unicode(keyword)
                    })
                return to_utf8(translate(msg))

        # Allow to use Wildcards, LDL and UDL values in calculations
        allowedwds = ["LDL", "UDL", "BELOWLDL", "ABOVEUDL"]
        keysandwildcards = re.compile(r"\[([^\]]+)\]").findall(value)
        keysandwildcards = [k for k in keysandwildcards if "." in k]
        keysandwildcards = [k.split(".", 1) for k in keysandwildcards]
        errwilds = [k[1] for k in keysandwildcards if k[0] not in keywords]
        if len(errwilds) > 0:
            msg = _(
                "Wildcards for interims are not allowed: ${wildcards}",
                mapping={
                    "wildcards": safe_unicode(", ".join(errwilds))
                })
            return to_utf8(translate(msg))

The list "errwilds" will be filled if the key from keysandwildcards is not in keywords.

Expected behaviour

I would like to be able to use wildcards without passing the keyword separately.

Versions

  • OS: Linux

  • senaite.core: master

  • senaite.impress: master

  • senaite.core.listing: master

  • senaite.core.supermodel: master

RML-IAEA avatar Nov 29 '22 16:11 RML-IAEA