-
Notifications
You must be signed in to change notification settings - Fork 11
Enhance validation for graph checks error messages #142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Enhance validation for graph checks error messages #142
Conversation
License Check Results🚀 The license check job ran with the Bazel command: bazel run //src:license-check Status: ✅ Passed Click to expand output
|
The created documentation from the pull request is available at: docu-html |
oper: dict[str, Any] = { | ||
"and": operator.and_, | ||
"or": operator.or_, | ||
"not": operator.not_, | ||
"not": lambda x: not x, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expaline why this is needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I was checking if there is other changes I need to make in graph_checks.py to make the tests works I found that Python’s operator.not_ actually expects a single operand, but its behavior can be a bit inconsistent with non-boolean types.
Using lambda x: not x is a safer and more explicit way to handle the logical not operation on evaluated conditions.
I’ve replaced operator.not_ with lambda x: not x for clarity and correctness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give me some examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 'operator.not_' works only with boolean inputs. It expects a direct boolean value like True or False.
However, in our function, the evaluated condition might not be a pure boolean — it might be a string, number, or even a None, which Python treats as "falsy" or "truthy" in logical contexts.
Here are some Examples:
```' # Example 1 print(operator.not_(True)) # ✅ Works → False print(operator.not_(False)) # ✅ Works → True # Example 2 - Non-boolean print(operator.not_("status")) # ✅ Works → False print(operator.not_("")) # ✅ Works → True # BUT... # Example 3 - What if we accidentally give a list or dict? print(operator.not_({"key": "value"})) # ❌ Technically works (False), but semantically risky '''
-
'operator.not_ 'doesn’t do type checking, and in more complex condition trees, it's harder to ensure only boolean values are passed.
In our recursive eval_need_condition, the return value might not always be strictly boolean, leading to unclear behavior or silent logic errors. -
'lambda x: not x' is safer as it ensures you're explicitly controlling the context — Python's native not works on any type and follows standard truthy/falsy semantics just like Python developers expect. It also reads more clearly when debugging or tracing the logic.
if cond == "not": | ||
if not isinstance(vals, list) or len(vals) != 1: | ||
raise ValueError("Operator 'not' requires exactly one operand.") | ||
return oper["not"](eval_need_condition(need, vals[0], log)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For sure it's a suggestion and I can roll back the changes if needed.
parent_ids = need[parent_relation] | ||
if not isinstance(parent_ids, list): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't quiet understand this?
What's the pourpes of this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to ensure it's a list, as we are going to loop through it, but I have removed this if statement now
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically it makes sense, though if this weren't a list then we have much bigger problems, as that means the Metamodel loaded wrong.
If you truly want you can make this as an 'assert' here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will just keep it simple and remove the if there is no need for an assert I guess
@@ -714,13 +714,15 @@ graph_checks: | |||
condition: safety == QM | |||
check: | |||
satisfies: safety == QM | |||
explanation: An ASIL requirement must link at least one parent/upstream ASIL requirement for correct decomposition. Please ensure the parent’s safety level is QM and its status is valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Status valid is not checked here.
Though it will be in the future as far as I know. So I think we should keep this Explanation for now
# If need-req is `ASIL_B`, parent must be `QM` or `ASIL_B`. | ||
req_safety_linkage_asil_b: | ||
needs: | ||
include: comp_req, feat_req | ||
condition: safety == ASIL_B | ||
check: | ||
satisfies: safety != ASIL_D | ||
explanation: An ASIL requirement must link at least one parent/upstream ASIL requirement for correct decomposition. Please ensure the parent’s safety level is not ASIL_D and its status is valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing that this only applies when current requirement is ASIL_B, not whne it's QM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
@@ -732,3 +734,4 @@ graph_checks: | |||
condition: safety == ASIL_B | |||
check: | |||
mitigates: safety != QM | |||
explanation: An ASIL requirement must link at least one parent/upstream ASIL requirement for correct decomposition. Please ensure the parent’s safety level is not QM and its status is valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't make sense.
explanation: An ASIL requirement must link at least one parent/upstream ASIL requirement for correct decomposition. Please ensure the parent’s safety level is not QM and its status is valid. | |
explanation: An ASIL_B safety requirement must link to a ASIL_B requirement. Please ensure that the linked requirements safety level is not QM and it's status is valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but here also we it can be equal or higher so must link to ASIL_B or ASIL_D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASIL_D is no longer available to be choosen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions. See Comments
Edit: Also, formatting missing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some comments
Adding Attribute explanation to the graph checks in the metamodel
Extract the explanation attribute and add it to the log when we have errors for graph checks
Assert to ensure the explanation attribute is there
Adapt the RST Tests to the new log error format output
close: #115