Closed rhpvorderman closed 6 years ago
@rhpvorderman great comment, I don't think there's an especially nice workaround to this right now.
This is caused because defined
operates on optional values (eg File?
) whereas object member accesses either returns a value, or fail the workflow. We could fix this in a couple of ways:
hasKey(object, key)
method for objects, roughly equivalent to how you're trying to use defined
. getPath(object, path)
method that returns an optional value which is set if the path exists in the object, or empty if it isn't.And with my apologies, I'm now going to immediately redirect you elsewhere...
Since any of the above suggestions would require a change to the WDL spec, I suggest you open this as a new issue in that repo. Once the change is accepted there I'll be able to make a new issue here to implement the change in Cromwell.
One other comment, I'd suggest you check out (and maybe vote on) the proposed addition of structs in this PR in openWDL: https://github.com/openwdl/wdl/pull/160
If the PR passes, it's possible your problem might be fixed without needing further spec changes. You'll be able to define a Centrifuge
struct like this:
struct Centrifuge {
String? database
# ... other fields
}
If you had this then the defined
method would be able to key off the database
field (which would always have a value, either set to a string, or set to a null).
This isn't part of the WDL spec yet, but it's very close, so watch out for it!
Thank you @cjllanwarne . A Struct
would be indeed a nicer way to fix this as you can define all the items. An object
can then be used for simpler things. Extra methods just add clutter. I will check it out.
EDIT: on second thought, best to leave this issue open until structs are actually there.
Structs are there.
In the following code snippet:
The
centrifugeList
is a list of dictionaries. The resultingcentrifuge
object
may or may not have a key database.Expected behaviour:
database
defaults to"refseq"
if nodatabase
key is present in the dictionary. It will use the database key if it exists.Observed behaviour: