Validation rule for a property containing another property's name causes a problem

Using OpenTap 9.17.4 and I couldn’t see this issue reported or fixed in newer releases. My apologies if it is already fixed or reported.

Developing plugins on Python; when adding validation rules for multiple properties, if a property (e.g., sweep_points) contains another property’s name (e.g., sweep), the error message specific to that containing the other property’s name is displayed also for the other property. Below you can see the code and the screenshots related to this issue.

Properties added:

self.AddProperty("sweep", 0, UInt32)\
            .AddAttribute(DisplayAttribute, "Sweep Counts", "The number of sweeps to be used to average traces.",
                          Groups=self.SWEEP_GROUP, Order=4.2)
self.AddProperty("sweep_points", 1001, UInt32)\
            .AddAttribute(DisplayAttribute, "Sweep Points", "The number of points to be analyzed per sweep.",
                          Groups=self.SWEEP_GROUP, Order=4.3)

Validation rules added:

self.AddRule(lambda: 0 <= self.sweep <= self.MAX_SWEEP_COUNT,
             lambda: f"Number of sweeps should be between 0 and {self.MAX_SWEEP_COUNT}", "sweep")
self.AddRule(lambda: self.MIN_SWEEP_POINT <= self.sweep_points <= self.MAX_SWEEP_POINT,
             lambda: f"Number of sweep points should be between {self.MIN_SWEEP_POINT} and "
                     f"{self.MAX_SWEEP_POINT}", "sweep_points")
  1. The error message propagated to the input (sweep) which has nothing to do with this validation rule
  2. The error message for the input (sweep_points) where the rule is violated

As I tested other possibilities, sharing a substring (e.g., sweep_points and sweep_time) does not cause the same problem. It only occurs if a property has another property’s name in its name as a substring. I would appreciate if you can help on this issue!

1 Like

I took a look at the code and can verify that something like this might be happening due to a bug in the code.

I have added an issue here: Python 2.4.1: Validation error is shown on wrong property · Issue #42 · opentap/OpenTap.Python · GitHub

Maybe you could try changing this line in

 filteredRules = dict(filter(lambda item: str(propertyName) in item[0], self.__ruleCollection.items()))


 filteredRules = dict(filter(lambda item: str(propertyName) == item[0], self.__ruleCollection.items()))
1 Like

Thank you for your response. I tried out what you suggested but could not get it working and looking at the code it makes sense why it would not work. Because __ruleCollection dictionary has its keys as {propertyName}-{hash(rule)} (e.g. sweep-012891328). Therefore, something like below would work as expected:

        filteredRules = dict(filter(lambda item: str(propertyName) == item[0].split("-")[0],
1 Like

OK, this sounds reasonable too. I hadent looked at how __ruleCollection was being populated.

1 Like