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

Fix an issue with Click 8.0.0 for custom type double-conversion #769

Merged
merged 1 commit into from
May 13, 2021
Merged

Conversation

nolar
Copy link
Owner

@nolar nolar commented May 13, 2021

Presumably caused by this change in Click:

… This ensures the default value is processed like other values. Some type converters were adjusted to accept values that are already the correct type. …

Previously, the default string was converted to the default value of the parameter only once. With Click 8.0.0, first, the default string ("full") is converted to its typed (enum), and then its enum is converted again as a regular value.

According to the docs (from a quote below), this is a violation of the conversion contract from Click's side — i.e. not only a string is passed:

… To implement a custom type, you need to subclass the ParamType class. Override the convert() method to convert the value from a string to the correct type. … https://click.palletsprojects.com/en/7.x/parameters/#implementing-custom-types

With this fix, if a value is already of the proper type, do not convert it and use it "as is".

As an immediate workaround for bleeding cases when Kopf upgrade is not possible and older versions are required, restrict click<8.0.0 in your requirements.

Fixes #767. Replaces #768.

Presumably caused by this change in Click:

* pallets/click@e79c2b4

> … This ensures the default value is processed like other values. Some type converters were adjusted to accept values that are already the correct type. …

Previously, the default string was converted to the default value of the parameter only once. With Click 8.0.0, first, the default string ("full") is converted to its typed (enum), and then its enum is converted again as a regular value.

According to the docs (from a quote below), this is a violation of the conversion contract from Click's side — i.e. not only a string is passed:

> … To implement a custom type, you need to subclass the ParamType class. Override the convert() method to convert the value **from a string to the correct type**. … https://click.palletsprojects.com/en/7.x/parameters/#implementing-custom-types

With this fix, if a value is already of the proper type, do not convert it and use it "as is".

Signed-off-by: Sergey Vasilyev <nolar@nolar.info>
@nolar nolar added bug Something isn't working critical labels May 13, 2021
@nolar nolar merged commit c221619 into main May 13, 2021
@nolar nolar deleted the click8 branch May 13, 2021 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working critical
Projects
None yet
Development

Successfully merging this pull request may close these issues.

kopf run does not work with click 8.x
1 participant