Skip to content
This repository has been archived by the owner on Sep 7, 2023. It is now read-only.

Optional DateTime always return TRUE for some(myDate) #851

Open
martinhalford opened this issue Feb 25, 2022 · 3 comments
Open

Optional DateTime always return TRUE for some(myDate) #851

martinhalford opened this issue Feb 25, 2022 · 3 comments

Comments

@martinhalford
Copy link
Member

martinhalford commented Feb 25, 2022

Bug Report 🐛

Please see LOOM video for demo of bug.
https://www.loom.com/share/4d628fd1e1ec4afa9d5a50444e69ebe9

In summary, optional variables return unexpected results when interrogated in code blocks within grammar.tem.md files.

An optional DateTime variable myDate is defined as:

 o DateTime myDate optional

A value in the data.json file is set as...

"myDate": "2000-01-01T00:00:00"

A code block is defined in the grammar.tem.md as:

{{%
    match some(myDate)
    with let? completionDate then "YES - Found myDate - " ++ toString(myDate)
    else "NO - myDate not found"
%}}

A draft command is executed as:

cicero draft --template . --data ./data.json  --unquoteVariables

and the following response is returned...

YES - Found myDate - {"$left": 01/01/2000}

When the myDate value is deleted from data.json and the same draft command executed then the following response is returned.

YES - Found myDate - {"$right": null}

Expected Result

If myDate present then expected

YES - Found myDate - 01/01/2000

If myDate not present then expected

NO - myDate not found

Example CTA archive attached:
OptionalDateTime CTA

@ritikBhandari
Copy link

Is this issue still prevalent? Are you still facing it?

@prekel
Copy link

prekel commented Jul 5, 2022

You shouldn't match on some(myDate), because in this case expression some(myDate) will always has value and completionDate will have type DateTime optional. Your code snipped is equivalent to just

{{%
    "YES - Found myDate - " ++ toString(myDate)
%}}

Match should be done on myDate itself:

{{%
    match myDate
    with let? completionDate then "YES - Found myDate - " ++ toString(completionDate)
    else "NO - myDate not found"
%}}

Converting optional value to string is quite ugly, yes.

prekel added a commit to prekel/ergo that referenced this issue Jul 6, 2022
@shubhamkumar13
Copy link

shubhamkumar13 commented Jul 10, 2022

I agree with @prekel here some(MyDate) shouldn't be pattern matched here.

@prekel can you please create a PR (if you are willing to) for the tests that you added to the your fork I think that would be helpful in avoiding this 😃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants