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

Contract execution should return the validated request instead of the input request #643

Closed
jeromesimeon opened this issue Apr 14, 2021 · 11 comments
Labels
Difficulty: Starter Type: Feature Request 🛍️ New feature or request Type: Question ❓ Further information is requested

Comments

@jeromesimeon
Copy link
Member

jeromesimeon commented Apr 14, 2021

Description

Currently, Cicero contract execution returns the input request rather than the request after validation. This means we do not have default values, identifiers, or timestamps. This is inconsistent with what we do on responses, so looks a little odd:

zsh-5.8$ cicero trigger 
5:25:48 PM - INFO: Using current directory as template folder
5:25:48 PM - INFO: Loading a default text/sample.md file.
5:25:48 PM - INFO: Loading a default request.json file.
5:25:49 PM - WARN: A state file was not provided, initializing state. Try the --state flag or create a state.json in the root folder of your template.
5:25:49 PM - INFO: 
{
  "clause": "helloworld@0.14.0-2dcb5ab1574c3f6e1bb3c0f7afbebc7123953a67348eb1651010a16061e1a40d",
  "request": {
    "$class": "org.accordproject.helloworld.MyRequest",
    "input": "Accord Project"
  },
  "response": {
    "$class": "org.accordproject.helloworld.MyResponse",
    "output": "Hello Fred Blogs Accord Project",
    "$timestamp": "2021-04-14T17:25:49.221-04:00"
  },
  "state": {
    "$class": "org.accordproject.runtime.State",
    "$identifier": "d0c8e60f-eff5-419f-b122-5580ad7b5a8e"
  },
  "emit": []
}

[Notice: response has a $timestamp but request does not]

It might be preferable to return the validated request. What do people think?

@jeromesimeon jeromesimeon added Type: Feature Request 🛍️ New feature or request Type: Question ❓ Further information is requested Difficulty: Starter labels Apr 14, 2021
@jeromesimeon
Copy link
Member Author

@jeromesimeon
Copy link
Member Author

@mttrbrts @dselman @martinhalford would love some user-level feedback on this.

@mttrbrts
Copy link
Member

I can't see an issue with this. The interaction model is a synchronous request/response and the client will always have the original request instance.

Are there any instances where values from the input could be changed by validation, or is validation always additive?

@jeromesimeon
Copy link
Member Author

jeromesimeon commented Apr 14, 2021

I can't see an issue with this. The interaction model is a synchronous request/response and the client will always have the original request instance.

Are there any instances where values from the input could be changed by validation, or is validation always additive?

That is a really interesting question...

Besides default values... all I can think of:

  1. date time values will be normalised to ISO format in the specified utcOffset timezone
  2. foo:null things will be removed (I wished it was the other way around -- See Runtime execution over missing fields when field is optional concerto#197)
  3. Double values will be normalised...

So depending on how you think of additive, it's not entirely additive.

@jeromesimeon
Copy link
Member Author

I can't see an issue with this. The interaction model is a synchronous request/response and the client will always have the original request instance.

Are there any instances where values from the input could be changed by validation, or is validation always additive?

Interestingly, there isn't an easy way for the application to get the validated request (would currently need a separate call to the validator).

@martinhalford
Copy link
Member

This hasn't (so far) been an issue for us. However, if the request object is modified by the validator then I'd certainly like to see what was actually processed by Cicero. I can imagine some scenarios where an obscure bug might be obfuscated if the contract template developer is looking at the stale request object and not realising this might be different to what Cicero executed. Thoughts?

@mttrbrts
Copy link
Member

@jeromesimeon can you clarify, is the validated output request object actually the same as the input to the engine? I.e. validation happens before and after execution?

For example, to @martinhalford's question, this is a concern, and area for weird bugs, but it's no different than what we have already on the input side.

@ShubhamPalriwala
Copy link

Are we open to any solutions for this? I feel that sending the request object is relevant and would make sense as mentioned before by @jeromesimeon!

@Jeevan-Kiran-Lenka
Copy link

Hey!! I'm a new member of this wonderful community, I would like to work on this issue if it's still open or any beginner-friendly issue you guys can suggest.

@Hrushi20
Copy link

Hrushi20 commented Feb 6, 2022

This is the output of the request before validation.

{
  '$class': 'org.accordproject.helloworld.MyRequest',
  input: 'Accord Project'
}

This is the output of the verified request after validation.

{
    '$class': {
      '$coll': [ 'org.accordproject.helloworld.MyRequest' ],
      '$length': 1
    },
    '$data': {
      input: 'Accord Project',
      '$timestamp': d {
        '$L': 'en',
        '$d': 2022-02-06T19:05:50.467Z,
        '$x': [Object],
        '$y': 2022,
        '$M': 1,
        '$D': 7,
        '$W': 1,
        '$H': 0,
        '$m': 35,
        '$s': 50,
        '$ms': 467,
        '$offset': 330
      }
    }
}

In which format do I display the validated response? The validateInput function returns the above format of the validated request.
Do I need to modify the validated request object and display it?

Thank You

@jeromesimeon
Copy link
Member Author

Fixed in #731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Starter Type: Feature Request 🛍️ New feature or request Type: Question ❓ Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants