-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
fix(sdk.v2): Component is invalid if packages_to_install
empty and install_kfp_package=False
#6527
Conversation
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 What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
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 Once the patch is verified, the new status will be reflected by the 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. |
@googlebot I signed it! |
packages_to_install
empty and install_kfp_package=False
packages_to_install
empty and install_kfp_package=False
@@ -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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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:
pipelines/sdk/python/kfp/v2/components/component_factory.py
Lines 154 to 158 in 2f19a26
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
d83933d
to
0fe114a
Compare
/ok-to-test |
There was a problem hiding this 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: |
There was a problem hiding this comment.
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.
490b4bf
to
667393e
Compare
If an empty list is provided no command should be returned to avoid a broken command eg. `pip install `
667393e
to
519751d
Compare
There was a problem hiding this 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)) |
There was a problem hiding this comment.
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.
[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 |
/retest |
1 similar comment
/retest |
Description of your changes:
Add test for empty
packages_to_install_command
Don't return
pip install
with no packagesIf an empty list is provided no command should be returned to avoid a
broken command eg.
pip install
Checklist: