question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Constructing dsl.ContainerOp instance directly in user code doesn't always raise the warning.

See original GitHub issue

What steps did you take:

Compile the following pipeline

import kfp


def _sample_component_op(
    name: str, run_id: str, sample_metric_value: float
) -> kfp.dsl.ContainerOp:
    arguments = [run_id, sample_metric_value]
    return kfp.dsl.ContainerOp(
        name=name,
        image='library/hello-world:latest',
        arguments=arguments,
    )


@kfp.dsl.pipeline(name='minimul')
def sample_pipeline(
    run_id: str = kfp.dsl.RUN_ID_PLACEHOLDER,
    sample_metric_value: float = 0.5,
):
    """Execute main procedure of the pipeline."""
    _sample_component_op("component", run_id, sample_metric_value)

What happened:

No warning raised on using ContainerOp directly.

What did you expect to happen:

Seeing the following warning:

/usr/local/lib/python3.7/dist-packages/kfp/dsl/_container_op.py:1039: FutureWarning: Please create reusable components instead of constructing ContainerOp instances directly. Reusable components are shareable, portable and have compatibility and support guarantees. Please see the documentation: https://www.kubeflow.org/docs/pipelines/sdk/component-development/#writing-your-component-definition-file The components can be created manually (or, in case of python, using kfp.components.create_component_from_func or func_to_container_op) and then loaded using kfp.components.load_component_from_file, load_component_from_uri or load_component_from_text: https://kubeflow-pipelines.readthedocs.io/en/stable/source/kfp.components.html#kfp.components.load_component_from_file
  category=FutureWarning,

KFP SDK version: 1.4.0

Anything else you would like to add:

For comparison, compiling the following example raises the warning as expected.

import kfp

@kfp.dsl.pipeline(name='hello-world-pipeline')
def sample_pipeline():
  kfp.dsl.ContainerOp(
      name='hello-world',
      image='library/hello-world:latest',
      arguments=[],
  )

/kind bug /area sdk

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
AseiSugiyamacommented, Mar 15, 2021
1reaction
munagekarcommented, Mar 13, 2021

I also see that when the warning is shown it’s only shown once (in a Jupyter session).

This is the usual behavior with python warnings. Warning in a loop get called once only.

This is really weird. Unlike DeprecationWarning, FutureWarning should always be shown

https://docs.python.org/3/library/warnings.html#default-warning-filter This is correct, however this is not a python issue.

I have investigated this further, the reason the compiler doesn’t produce the warning is because the code in the first case does not reach the warning. The attached screenshot explains it further.

https://github.com/kubeflow/pipelines/blob/a12e88d1da57b897a3a25b5c44540fc7d3c9a40e/sdk/python/kfp/dsl/_container_op.py#L1104-L1105

The core issue is that __eq__ in kfp.dsl._pipeline_param.PipelineParam is incorrectly returning NamedTuple. __eq__ should return either True or False. A named tuple is assumed to be True. https://github.com/kubeflow/pipelines/blob/67afca4938c35e6b8be29e61df3883af11554220/sdk/python/kfp/dsl/_pipeline_param.py#L227-L228

Screen Shot 2021-03-13 at 2 11 15

Read more comments on GitHub >

github_iconTop Results From Across the Web

kfp.dsl._container_op — Kubeflow Pipelines documentation
def _wrapped(*args, **kwargs): warnings.warn( '`dsl. ... Example:: from kfp.dsl import ContainerOp from kubernetes.client.models import V1EnvVar # creates a ...
Read more >
How to use the kfp.dsl.ContainerOp function in kfp - Snyk
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >
Chapter 4. Kubeflow Pipelines - O'Reilly
An SDK for defining, building, and deploying pipelines in Python. Notebook support for using the SDK and pipeline execution. The easiest way to...
Read more >
dsl.ContainerOp with python - kubernetes - Stack Overflow
To kickstart KFP development using python, try the following tutorial: Data passing in python components. it clones the code before running ...
Read more >
Data Science on Steroids with Kubeflow | by Sascha Grunert
As a data scientist we also have no direct influence on this source. So for example, we could always use the latest database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found