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

struct with optional fields #686

Closed
adthrasher opened this issue Apr 30, 2024 · 2 comments
Closed

struct with optional fields #686

adthrasher opened this issue Apr 30, 2024 · 2 comments
Labels
bug Something isn't working interop Bears on spec compatibility
Projects

Comments

@adthrasher
Copy link

I have run into a potential issue when using a struct that contains optional fields.

For example, consider this WDL document.

version 1.1

struct ReadGroup {
    String ID
    String? BC
    String? CN
    String? DS
    String? DT
    String? FO
    String? KS
    String? LB
    String? PG
    Int? PI
    String? PL
    String? PM
    String? PU
    String? SM
}

task test_task {
    input {
        ReadGroup read_group 
    }

    command <<<
        if [ -z "~{read_group.KS}" ]
        then
            echo "KS is empty"
        fi  
    >>>
}

I have a struct that represents a SAM read group. When I run miniwdl check, there are no issues reported. However, if I then run miniwdl, with the following input json:

{
    "read_group": {
        "ID": "test"
    }
}

I get an error (Token('CNAME', 'KS')) at ~{read_group.KS}. I have tried alternative methods such as ~{if defined(read_group.KS) then read_group.KS else ""} and ~{select_first([read_group.KS, ""])} which both have the same issue.

Based on the error and the fact that it only occurs at runtime, is it possible that the KS field is not being created on the internal data structure so miniwdl doesn't recognize that token? I would expect that it would exist and simply be undefined similar to other optional variables, but that doesn't seem to be the case.

@mlin mlin added the bug Something isn't working label Apr 30, 2024
@mlin mlin added this to Backlog in miniwdl via automation Apr 30, 2024
@mlin mlin added the interop Bears on spec compatibility label Apr 30, 2024
@mlin mlin moved this from Backlog to In progress in miniwdl Apr 30, 2024
mlin added a commit that referenced this issue May 1, 2024
Populate optional fields with None values when the input JSON omits them. This was done for `read_json()`, but not the case where the struct is read from a runner input JSON file.

#686
@mlin mlin moved this from In progress to Pending release in miniwdl May 1, 2024
@mlin
Copy link
Collaborator

mlin commented May 1, 2024

Thanks @adthrasher, your diagnosis was correct in the case where the struct is initialized from the runner input JSON file. I've checked in a fix.

@adthrasher
Copy link
Author

Excellent! As always, thanks for the rapid response and fix!

@mlin mlin closed this as completed May 13, 2024
miniwdl automation moved this from Pending release to Done May 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working interop Bears on spec compatibility
Projects
miniwdl
  
Done
Development

No branches or pull requests

2 participants