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(sdk.v2): Component is invalid if packages_to_install empty and install_kfp_package=False #6527

Merged
merged 1 commit into from
Sep 16, 2021

Conversation

judahrand
Copy link
Contributor

@judahrand judahrand commented Sep 8, 2021

Description of your changes:

  • Add test for empty packages_to_install_command

  • Don't return pip install with no packages

    If an empty list is provided no command should be returned to avoid a
    broken command eg. pip install

Checklist:

@google-cla
Copy link

google-cla bot commented Sep 8, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-oss-robot
Copy link

Hi @judahrand. Thanks for your PR.

I'm waiting for a kubeflow member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@judahrand
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Sep 8, 2021
@judahrand judahrand changed the title fix(sdk): Component is invalid if packages_to_install empty and install_kfp_package=False fix(sdk.v2): Component is invalid if packages_to_install empty and install_kfp_package=False Sep 8, 2021
@@ -1158,6 +1158,12 @@ def test_packages_to_install_feature(self):
self.helper_test_component_using_local_call(
task_factory2, arguments={}, expected_output_values={})

task_factory3 = comp.func_to_container_op(
dummy_in_0_out_0, packages_to_install=[], install_kfp_package=False)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func_to_container_op doesn't have the install_kfp_package argument.
Besides, I don't think any test under this folder would cover your change under v2/components.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, let me remove the commit which adds this test. Do you think this is worth adding a test for?
It certainly caused me problems...

@@ -35,7 +35,7 @@ def _python_function_name_to_component_name(name):
def _get_packages_to_install_command(
package_list: Optional[List[str]] = None) -> List[str]:
result = []
if package_list is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty list is a user input, while None is the default value by the system. I thinks it's fine to make this change, but arguably empty list is a user error we don't necessarily need to catch - user could also provide a list of invalid packages.

Copy link
Contributor Author

@judahrand judahrand Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not true, see:

packages_to_install = packages_to_install or []

In the code the None is replaced with an empty list anyway. So leaving the default None will result in the empty list if install_kfp_package is False.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, maybe an alternative change it to move packages_to_install = packages_to_install or [] on line 154 to line 158:

packages_to_install = packages_to_install or []
if install_kfp_package:
if kfp_package_path is None:
kfp_package_path = _get_default_kfp_package_path()
packages_to_install.append(kfp_package_path)

WDYT?

Copy link
Contributor Author

@judahrand judahrand Sep 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think I prefer the current change and would maybe also remove the Optional from _get_packages_to_install_command.

Imo _get_packages_to_install_command should have enough logic (and does) to identify when there are no packages (empty list). It accepting a None type too just muddies the water in my mind. I'm not sure I really understand the advantage of it taking None

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It accepting a None type too just muddies the water in my mind. I'm not sure I really understand the advantage of it taking None

Please don't remove the Optional. It's not a good idea to use mutable objects as default arguments:
https://google.github.io/styleguide/pyguide.html#212-default-argument-values

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer the alternative change I mentioned above, in which way packages_to_install == None indicates system default, whereas packages_to_install == [] must be from user input.

That said, I'm fine with the current change as well.

Copy link
Contributor Author

@judahrand judahrand Sep 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neuromage That's not what I was suggesting at all! I'm fully aware that mutable default args are a very bad idea.

My suggestion was simply to remove the Optional type hint on _get_packages_to_install_command to make it clear that a list is expected.

It's a private function (as much as such a thing exists in Python) which is only used internally so there's not really a good reason for the Optional in my mind. And it already doesn't have a default value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a private function (as much as such a thing exists in Python) which is only used internally so there's not really a good reason for the Optional in my mind. And it already doesn't have a default value.

Optional[...] is just a shorthand for Union[None, ...], it has nothing to do with default value. With the alternative change I commented above, we would get None--the default value from the public method--passed all the way through to this point. So Optional would make sense.

@judahrand judahrand force-pushed the bug/packages-to-install branch from d83933d to 0fe114a Compare September 9, 2021 22:12
@neuromage
Copy link
Contributor

/ok-to-test

Copy link
Member

@chensun chensun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @judahrand, can you please add an entry for this PR in the SDK release note: https://github.com/kubeflow/pipelines/blob/master/sdk/RELEASE.md

@@ -35,7 +35,7 @@ def _python_function_name_to_component_name(name):
def _get_packages_to_install_command(
package_list: Optional[List[str]] = None) -> List[str]:
result = []
if package_list is not None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I personally prefer the alternative change I mentioned above, in which way packages_to_install == None indicates system default, whereas packages_to_install == [] must be from user input.

That said, I'm fine with the current change as well.

@judahrand judahrand force-pushed the bug/packages-to-install branch from 490b4bf to 667393e Compare September 10, 2021 10:17
If an empty list is provided no command should be returned to avoid a
broken command eg. `pip install      `
@judahrand judahrand force-pushed the bug/packages-to-install branch from 667393e to 519751d Compare September 14, 2021 08:05
Copy link
Member

@chensun chensun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

Thanks!

@@ -11,6 +11,7 @@
## Deprecations

## Bug Fixes and Other Changes
* Fix component decorator could result in invalid component if `install_kfp_package=False`. [\#6527](https://github.com/kubeflow/pipelines/pull/6527))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: there's extra ) at the end. I'll fix it later when doing the release.

@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: chensun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@chensun
Copy link
Member

chensun commented Sep 15, 2021

/retest

1 similar comment
@chensun
Copy link
Member

chensun commented Sep 15, 2021

/retest

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

Successfully merging this pull request may close these issues.

4 participants