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

Unexpected value for default bool? parameter #1498

Open
paralaxsd opened this issue Dec 23, 2024 · 2 comments
Open

Unexpected value for default bool? parameter #1498

paralaxsd opened this issue Dec 23, 2024 · 2 comments
Labels

Comments

@paralaxsd
Copy link

paralaxsd commented Dec 23, 2024

Usage Information

9.0.3 / net9.0

Description

I have defined a [Parameter] value of type bool? to indicate an optional build property.
It has null as default value which works as expected when testing the behavior locally.

However, I have also enabled Team City integration and as such, an environment variable named according to my parameter is automatically associated with my target's build configuration. Team City sets the associated environment variable to an empty string via the generated Kotlin script.

When my nuke target is run on CI, the bool? parameter is automatically parsed from this empty environment variable and somewhat surprisingly ends up being false rather than null.

This behavior seems to have changed and was originally working as I would expect. My issue seems to have been introduced when updating Nuke from v8.0.0 to v8.1.2 and it's like this up to the current version 9.0.3.

Reproduction Steps

  • Define a [Parameter] attributed field readonly bool? TestBoolean;
  • Set the environment variable TestBoolean to an empty string and run nuke with any target.
  • Inside the target's Executes logic, refer to TestBoolean.

Expected Behavior

The value of the TestBoolean field is null.

Actual Behavior

The value of the TestBoolean field is false.

Regression?

No response

Known Workarounds

One can of course define the parameter field as string? and try-parse the value manually.

Could you help with a pull-request?

No

@paralaxsd paralaxsd added the bug label Dec 23, 2024
@Roadrunner67
Copy link
Contributor

@paralaxsd The current implementation only returns null on bool? parameters if the parameter neither exists on command line nor in environment variables.
If it DOES exists it must be either true or false.
Even when "it used to work", I think it is risky to assume anything based on a null-value boolean, I would go for a different solution.

@paralaxsd
Copy link
Author

The current implementation only returns null on bool? parameters if the parameter neither exists on command line nor in environment variables.

Exactly. And since Team City exposes the env var unconditionally, Nuke picks up the empty bool? parameter as false.
I think this interplay is somewhat unexpected as it breaks nullable value type parameters in conjunction with Team City Kotlin script generation.

Perhaps interpreting the empty string as null for nullable value types could be a viable way to support this scenario? Just food for thought.

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

No branches or pull requests

2 participants