cdisc-org / cdisc-rules-engine

Open source offering of the cdisc rules engine
MIT License
49 stars 13 forks source link

Rule blocked: CORERULES-9617 - validation fails when operation references a domain that does not exist #917

Open ASL-rmarshall opened 5 days ago

ASL-rmarshall commented 5 days ago

Links to related JIRA Tickets

Rule Information

Describe the bug This rule is checking whether the number of records describing study interventions (from the StudyIntervention dataset) corresponds with the value of the interventionModel code or decode. The rule works correctly when there is a StudyIntervention dataset, but it fails with the following error when there is no StudyIntervention dataset:

argument of type 'NoneType' is not iterable.

The error occurs because the rule includes an operation that references the "STUDYINTERVENTION" domain but a corresponding dataset does not exist, which would be possible if the original USDM JSON file did not contain any instances of the StudyIntervention class.

The following is a stacktrace for the error:

Error: argument of type 'NoneType' is not iterable, line 252 in get_dataset_name_from_details Trace(1): <FrameSummary file C:\CDISC\cdisc-rules-engine\cdisc_rules_engine\rules_engine.py, line 168 in validate_single_rule> Trace(2): <FrameSummary file C:\CDISC\cdisc-rules-engine\cdisc_rules_engine\rules_engine.py, line 301 in validate_rule> Trace(3): <FrameSummary file C:\CDISC\cdisc-rules-engine\cdisc_rules_engine\rules_engine.py, line 340 in execute_rule> Trace(4): <FrameSummary file C:\CDISC\cdisc-rules-engine\cdisc_rules_engine\utilities\rule_processor.py, line 284 in perform_rule_operations> Trace(5): <FrameSummary file C:\CDISC\cdisc-rules-engine\cdisc_rules_engine\utilities\rule_processor.py, line 329 in _execute_operation> Trace(6): <FrameSummary file C:\CDISC\cdisc-rules-engine\cdisc_rules_engine\utilities\utils.py, line 252 in get_dataset_name_from_details>

It shows that validation is falling over when a None is passed into get_dataset_name_from_details, which expects a dictionary.

Error returned from Rule Engine

{
    "STUDYDESIGN": [
        {
            "executionStatus": "execution_error",
            "dataset": "StudyDesign.xpt",
            "domain": "STUDYDESIGN",
            "variables": [],
            "message": "rule execution error",
            "errors": [
                {
                    "dataset": "StudyDesign.xpt",
                    "error": "An unknown exception has occurred",
                    "message": "argument of type 'NoneType' is not iterable"
                }
            ]
        }
    ]
}

Expected behavior Instead of failing with an error, the validation should just skip any operation that references a domain that does not exist. This could be achieved by inserting the following between the assignment of domain_details and the call to get_dataset_name_from_details in _execute_operation (i.e., at line 329 in rule_processor.py):

            if domain_details is None:
                return dataset

In this case, if the referenced domain does not exist, the call to the operation just returns the original dataset (without the operation-specific id variable). The presence/absence of the result of the operation can then be checked in the rule condition (as shown in rule DDF00074 in the production environment or the attached Request.txt file).

ASL-rmarshall commented 5 days ago

Test data is available in Excel format in the unitTesting SharePoint under USDM > DDF00074. There are two negative test cases and one positive test case. It is only the negative test case 02 (where there is no StudyIntervention dataset) that fails as described above.