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

[Issue454]: Add validation that queries provide the correct parameters #455

Merged
merged 2 commits into from
Aug 26, 2020

Conversation

EthanEChristian
Copy link
Contributor

A PR for #454

@EthanEChristian
Copy link
Contributor Author

todos:
I need to add clearer explanations on both the clara site and the rule namespace as well, about how queries and the contract of queries are defined.

I am adding this review, to make sure everyone is ok with the changes prior to changing all the doc.

CHANGELOG.md Outdated
@@ -3,6 +3,7 @@ This is a history of changes to clara-rules.
# 0.21.0 SNAPSHOT
* Add names to anonymous functions generated by rule compilation, see [issue 261](https://github.com/cerner/clara-rules/issues/261) and [issue 291](https://github.com/cerner/clara-rules/issues/291)
* Add alpha node types, see [issue 237](https://github.com/cerner/clara-rules/issues/237)
* BREAKING: Validate parameters provided to queries exist on query and compilation. see [issue 454](https://github.com/cerner/clara-rules/issues/454)
Copy link
Collaborator

Choose a reason for hiding this comment

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

It may be better to not just call it breaking. It is in a sense, but previously you’d get no result basically. Perhaps mention? Or is the issue link enough I guess?

Copy link
Collaborator

Choose a reason for hiding this comment

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

For something like this where giving the now-breaking parameters would never have given meaningful result this might be a bit too much, but not really a big deal either way IMO. Maybe a phrase like "Throw exception on invalid..." to make clear that if users are giving correct input that they won't be impacted.

Copy link
Collaborator

Choose a reason for hiding this comment

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

+1 to the changes in b559d93

@@ -1986,6 +1986,9 @@
(let [query-node (get-in rulebase [:query-nodes query])]
(when (= nil query-node)
(platform/throw-error (str "The query " query " is invalid or not included in the rule base.")))
(when-not (= (into #{} (keys params)) ;; nil params should be equivalent to #{}
(:param-keys query-node))
(platform/throw-error (str "The query " query " was not provided with the correct parameters, expected: " (:param-keys query-node) ", provided: " (set (keys params)))))

Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit : Really long line?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this was resolved by the changes in b559d93

src/test/clojure/clara/test_compiler.clj Outdated Show resolved Hide resolved
Copy link
Collaborator

@WilliamParker WilliamParker left a comment

Choose a reason for hiding this comment

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

I had some minor suggestions mostly around phrasing of docs and error messages, but essentially this looks OK and merging it would be fine.

CHANGELOG.md Outdated
@@ -3,6 +3,7 @@ This is a history of changes to clara-rules.
# 0.21.0 SNAPSHOT
* Add names to anonymous functions generated by rule compilation, see [issue 261](https://github.com/cerner/clara-rules/issues/261) and [issue 291](https://github.com/cerner/clara-rules/issues/291)
* Add alpha node types, see [issue 237](https://github.com/cerner/clara-rules/issues/237)
* BREAKING: Validate parameters provided to queries exist on query and compilation. see [issue 454](https://github.com/cerner/clara-rules/issues/454)
Copy link
Collaborator

Choose a reason for hiding this comment

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

For something like this where giving the now-breaking parameters would never have given meaningful result this might be a bit too much, but not really a big deal either way IMO. Maybe a phrase like "Throw exception on invalid..." to make clear that if users are giving correct input that they won't be impacted.

src/main/clojure/clara/rules/compiler.clj Outdated Show resolved Hide resolved
src/test/clojure/clara/test_compiler.clj Outdated Show resolved Hide resolved
src/test/clojure/clara/test_compiler.clj Outdated Show resolved Hide resolved
@WilliamParker
Copy link
Collaborator

Re todos: +1 to clarifying the doc, but if the current state is that we're accepting query calls that won't actually return data properly I think throwing an exception on that is fine even prior to that - i.e. clarifying doc is a good idea but I personally don't think it is a blocker to merging this.

@EthanEChristian EthanEChristian changed the base branch from master to main July 9, 2020 15:17
@WilliamParker
Copy link
Collaborator

@EthanEChristian just wondering what your plans are with this one, if you're busy I could perhaps help with getting this over the finish line e.g. updating docs as it is quite close I think.

@WilliamParker
Copy link
Collaborator

+1 to merging this after the changes in b559d93

@EthanEChristian EthanEChristian merged commit 9ec34de into oracle-samples:main Aug 26, 2020
@EthanEChristian EthanEChristian deleted the ISSUE_454 branch August 26, 2020 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants