Skip to content
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

feat: Non-existing context entries result in null #696

Merged
merged 11 commits into from Sep 5, 2023

Conversation

saig0
Copy link
Member

@saig0 saig0 commented Jul 28, 2023

Description

  • Change the behavior to return null if a context doesn't contain an entry with the given key, or if the context is null. Previously, the evaluation failed in this case.
  • Write new test cases and adjust the expected behavior of existing test cases. Use the new evaluation result matcher in all test cases to verify reported failures, improve readability, and align the testing style.

Related issues

contributes to #674

@saig0
Copy link
Member Author

saig0 commented Jul 28, 2023

@korthout please review the PR in the next 4 weeks (or assign to someone else). 😉

@korthout korthout self-requested a review August 8, 2023 16:33
Copy link
Member

@korthout korthout left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice changes @saig0 🚀

👍 I especially like how the tests are becoming more expressive

🔧 I have just a few comments, but nothing blocking. Please have a look.

👍 LGTM

💭 As this behavior breaks user space (and regresses #695), there must be clear communication to users in the release notes about these changes. Perhaps this requires a major version bump. WDYT?

PS: Sorry for the late review

Comment on lines 878 to +882
error(
failureType = EvaluationFailureType.NO_CONTEXT_ENTRY_FOUND,
failureMessage = s"context contains no entry with key '$key'"
failureMessage = s"No context entry found with key '$key'. $detailedMessage"
)
ValNull
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Off-topic: I was wondering a bit about the usage of the implicit EvalContext and the return value of the error() function. The return value is now ignored because ValNull is returned instead. this works, but the error function is now used only for its 'side effect' (i.e. storing the error as a failure in the implicit evaluation context). It feels easy to use this way, but is this idiomatic Scala? Because this is a side-effect right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Valid point. 😅 This style is only temporary. After the remaining null-handling issues are resolved, I'll clean up the error part.

Add a test case to verify that the evaluation returns null if a context entry doesn't exist.
Change the behavior to return null if a context doesn't contain an entry with the given key, or if the context is null. Previously, the evaluation failed here.
Add a test case to verify that a context projection contains null if a context entry doesn't have the given key.

Group the new test case with the other context projection test cases.
Group all test cases related to context path expressions.
Group all test cases related to context filter expressions.
Use the new evaluation result matcher in all test cases to improve the readability and to align on one format.
The behavior for bean expressions (i.e. a special form of contexts) changed. If a field or method is not available/visible, the expression results in `null`. Previously, the evaluation failed.

Use the new base test class and the result matcher to improve the readability of the test cases.
The test case for the `is defined()` function doesn't work anymore because with the new behavior a non-existing context entry returns null. As a result, the function invocation returns `true` instead of `false`.

There is an issue to deal with the changed behavior of the function. See more here: #695.

Ignoring the test case until the issue is solved.
A non-existing context entry results in `null`. Rewrite the test case to keep the expectation that the evaluation fails.
The failure message for a non-existing context entry changed. Adjust the expected message of the test case.
Wrap available keys and properties inside single quotes to improve the readability of the message.
@saig0
Copy link
Member Author

saig0 commented Sep 5, 2023

💭 As this behavior breaks user space (and regresses #695), there must be clear communication to users in the release notes about these changes. Perhaps this requires a major version bump. WDYT?

I agree that we must be very clear with the communication and provide solutions. 👍

I don't see the need for a major version here. From the spec perspective, the current behavior is a bug and we're fixing the bug. In most cases, the impact on the user should be minor because the is defined() function is used in edge cases.

However, a major version would not help in the context of Camunda 8. I don't think that it would change something about the integration of the FEEL engine.

@saig0 saig0 merged commit 3af4ee3 into main Sep 5, 2023
5 checks passed
@saig0 saig0 deleted the 674-null-friendly-context branch September 5, 2023 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants