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

Time parameters like 4.d get parsed as double and fail schema validation #858

Closed
KevinMenden opened this issue Feb 17, 2021 · 18 comments
Closed
Assignees
Labels
bug Something isn't working high-priority

Comments

@KevinMenden
Copy link
Contributor

Description of the bug

Using e.g. --max_time 4.d throws a validation exception because the schema expects a string for --max_time
which should be granted by internal conversion of nextflow Duration objects to string, which seems to fail in this case

Steps to reproduce

Running a pipeline with the new parameter validation and a time parameter as described above should reproduce the bug.
I did it with a fresh template.

@KevinMenden KevinMenden added the bug Something isn't working label Feb 17, 2021
@KevinMenden
Copy link
Contributor Author

KevinMenden commented Feb 17, 2021

Some testing confirmed that it is indeed not caught by the cleanParameters function.

Adding

if (p['value'].getClass() == Double) {
    new_params.replace(p.key, p['value'].toString())
}

To that function captures the parameter, but converts it to 4.0 which then doesn't match the schema validation anymore.

@KevinMenden
Copy link
Contributor Author

Catching the double and then appending the .d back doesn't work by the way and is also way to hacky.

Given that you can just specify e.g. 72.h instead of 3.d we can live without the day version, but the error message might not be very clear to the user unfortunately.

@KevinMenden KevinMenden self-assigned this Mar 1, 2021
@ewels
Copy link
Member

ewels commented Mar 18, 2021

Did we solve this by changing how we specify dates in the end?

@KevinMenden
Copy link
Contributor Author

We might have ... wanted to spend some quality time with this issue during the hackathon.
I'm not too worried any more because I didn't run into this in the nextflow plugin tests.

@ewels
Copy link
Member

ewels commented Mar 30, 2021

Is this fixed by #974 ?

@ewels
Copy link
Member

ewels commented Mar 30, 2021

Nope:

$ nextflow run nf-core-testpipeline/ -profile test,docker --max_time 4.d
N E X T F L O W  ~  version 21.03.0-edge
Launching `nf-core-testpipelinee/main.nf` [nauseous_visvesvaraya] - revision: de1773e09a


------------------------------------------------------
                                        ,--./,-.
        ___     __   __   __   ___     /,-._.--~'
  |\ | |__  __ /  ` /  \ |__) |__         }  {
  | \| |       \__, \__/ |  \ |___     \`-._,-`-,
                                        `._,._,'
  nf-core/testpipelinee v1.0dev
------------------------------------------------------


ERROR: Validation of pipeline parameters failed!


* --max_time: expected type: String, found: Double (4.0)

@ewels
Copy link
Member

ewels commented Mar 30, 2021

I don't totally understand why 4.d gives a double and fails but 72.h works fine..? 🤔

@KevinMenden
Copy link
Contributor Author

KevinMenden commented Mar 30, 2021

Ah thanks for reminding me, need to have a closer look at this ...

I think it's because of the d (as in double), but that's just a suspicion

@KevinMenden
Copy link
Contributor Author

KevinMenden commented Mar 30, 2021

We could probably use the hack from above:

if (p['value'].getClass() == Double) {
    new_params.replace(p.key, p['value'].toString())
}

and fix the the resulting string to pass validation. This is as hacky as it gets though ... :/

@KevinMenden
Copy link
Contributor Author

KevinMenden commented Mar 30, 2021

Okay we can catch the parameter internally, fix it so it looks like a proper duration ("4.d") but then it still fails because it's already parsed as double internally and sets to run time limit to a rather short 4ms ...

It get's converted to 4.0 before the parameter validation, somewhere through the Nextflow/Groovy parsing process ...

It works when setting the parameter in nextflow.config, although then we get a 2.d instead of 4.d
So somewhere during the command line parsing the whole thing happens :/

@ewels
Copy link
Member

ewels commented Apr 3, 2021

@pditommaso have you seen this before? Nextflow time objects with days being parsed as a numeric double instead?

Sounds like it may be something that should be fixed upstream @KevinMenden..

@pditommaso
Copy link

pditommaso commented Apr 5, 2021

I think it conflicts with 'd' literal for double https://stackoverflow.com/a/27368444/395921. 1.day works tho.

Also try to avoid hacks like the following, looks very bad

if (p['value'].getClass() == Double) {
    new_params.replace(p.key, p['value'].toString())
}

@KevinMenden
Copy link
Contributor Author

Okay thanks - so then there's really nothing we can do here, except adapting the regex and use *.day instead, I guess.

Yes we're not using that, it doesn't really work anyway :) Although we use similar hacks to deal with the nextflow duration objects etc 👀 need to remove them before passing the object to the Schema validator

@ewels
Copy link
Member

ewels commented Apr 7, 2021

I didn't know about .day syntax - ok then yes let's just force people to use that 👍🏻

@ewels
Copy link
Member

ewels commented Apr 13, 2021

@pditommaso we just implemented this but ran into a problem - if a Nextflow config file uses a native memory variable type then Nextflow will automatically simplify this and uses the .d syntax.

params.some_time = 48.h
println(params.some_time)
$ nextflow run mem_test.nf
N E X T F L O W  ~  version 21.03.0-edge
Launching `mem_test.nf` [condescending_panini] - revision: 18bf7ca334
2d

So then we're kind of screwed as this then hits the string double parsing issue we see above. But there's nothing that we can do about it..

Is it possible to get Nextflow to use .day instead of .d as the primary unit type for these conversions?

@ewels
Copy link
Member

ewels commented Apr 14, 2021

x-ref nextflow-io/nextflow#2038

@ewels
Copy link
Member

ewels commented Apr 25, 2021

@KevinMenden @drpatelh - can this issue be closed now?

@drpatelh
Copy link
Member

Yes, I believe we fixed it in these PRs:
#1012
#1003

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high-priority
Projects
None yet
Development

No branches or pull requests

4 participants