-
Notifications
You must be signed in to change notification settings - Fork 80
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
refactor: handle "non"-validating output for async actions #1279
Conversation
I looked at how we can re-work I see some possible solutions:
What do people think? Any other ways to solve the problem? |
I extended |
I think changing the option to ignore validation is good but I am not sure about the async/sync action difference. Where do we say that async action's response is not the output? From my pov, it is the responsibility of the developer to make the difference and the output should contain the response to the invocation. |
The TD spec states the following
see https://w3c.github.io/wot-thing-description/#table-vocabulary-terms-in-actionaffordance-level This tells me that if the keyword |
There is no such thing as an "ActionStatus" object. It only exists in one profile. If that is a generic mechanism, it should be in the TD spec first. The main unclear part in the TD spec is the meaning of output "Used to define the output data schema of the Action.". Is output the result of the physical process? Is it protocol level response? |
I know. I used "ActionStatus" object as the term since it used in the profile and known by everyone. What I mean in general is that async operations do not send the value directly after calling Hence, the |
I understand but what if the intention is that output field matches the actionstatus object? For now, we can go with this direction but I think there is no consensus on this from the standardization perspective. |
Mhh, that sounds weird to me but I see now where you are coming from. Having said that, TD2.0 should have a way to describe both, the final output of an action and the "output" provided after invoking the action. |
Any more opinions on the PR? Is it the right way forward for now? |
We had a casual chat in the last committer meeting about this PR. One thing that we can improve is to introduce an options object as the last argument of InteractionOutput constructor. It should be a little more flexible for future improvements. Then we can expose that option in the |
An "option object" makes sense 👍 What I am not very sure about when reading your comments is
Once we can agree on the possible options I can update the PR accordingly. |
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.
Another minor point. I am not sure to leave the logic to automatically ignore validation if the action is asynchronous give @egekorkan's points. But we can remove it once we proper expose this ignoring feature to the end user.
@@ -122,14 +124,14 @@ export class InteractionOutput implements WoT.InteractionOutput { | |||
// validate the schema | |||
const validate = ajv.compile<T>(this.schema); | |||
|
|||
if (!validate(json)) { | |||
if (!this.ignoreValidation && !validate(json)) { |
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 would skip schema compilation since in the case of ingnoreValidation === true
is completely useless.
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.
Mhh, in the case of ignoreValidation === true
the part after &&
is no longer taken into account since the if
cannot turn into true
anymore?
Or did I misunderstand the comment?
@relu91 @egekorkan |
I think it is even better to turn of validation by default. Regarding the compilation of the schema or not, it is better not compile it but I am not sure if the JS engine respects the order and does not compile the second. It would be cleaner to check ignoreValidation first and then go the validation in another if branch? |
Turning it off for actions only all for all interactions like properties also? Mhh. We do have this for a very long time now and I do not fully understand why we disable it now (since a user is not possible to configure it). My take is that for property and event I would keep it. For action I would keep it also, if we know the action is synchronous.
I feel the opposite. It is surely the case that all following statements in a && sequence are not executed if a previous one is false (JS uses uses short circuit evaluation). |
I would not default to no validation either. I think we should discuss these changes in the next commiter meeting to better understand what to do next. There is also the fact that actually, users have already some options to avoid validation. I list some here that we can review. Defining a utility function
|
I think that's also fine. We should just document this approach. If we can log and point to documentation in case of validation failure, even better but it might be too verbose in logs |
After a loooong discussion and earing all the different points of view. We have chosen to go with adding a parameter to the value function to turn off validation. This will be useful for other use cases as well and has the advantage not to be verbose as For the future, invoking an async action might return a different object (not an InteractionOutput) where the application can call methods like |
FYI: I created 2 Scripting API issues: w3c/wot-scripting-api#554 and w3c/wot-scripting-api#555 |
Since I expect some time to pass before the proposed changes may land in the Scripting API. Do we still want to "fix" #1278 temporarily in one way or the other? |
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.
Given the discussion of today's committer meeting:
- TD spec is not clear about what to expect when the
sync
property is missing - Eargerly validate the output in this cases means to try out smart the developer which is quite a bad practice
- Therefore we decided to merge this PR as a workaround for the whole situation. We acknowledge that there needs to be follow up fixes both in Scripting API and Thing Description spec to properly solve the issue.
fixes #1278