<p>Copied from here: <a href="https://github.com/kubeflow/pipelines/issues/7608" rel="nofollow noreferrer">https://github.com/kubeflow/pipelines/issues/7608</a></p>
<p>I have a generated code file that runs against Kubeflow. It ran fine on Kubeflow v1, and now I'm moving it to Kubeflow v2. When I do this, I get the following error:
<code>json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)</code></p>
<p>I honestly don't even know where to go next. It feels like something is fundamentally broken for something to fail in the first character, but I can't see it (it's inside the kubeflow execution).</p>
<p>Thanks!</p>
<hr />
<h3>Environment</h3>
<ul>
<li><p>How did you deploy Kubeflow Pipelines (KFP)?
Standard deployment to AWS</p>
</li>
<li><p>KFP version:
1.8.1</p>
</li>
<li><p>KFP SDK version:
1.8.12</p>
</li>
</ul>
<p>Here's the logs:</p>
<pre><code>time=&quot;2022-04-26T17:38:09.547Z&quot; level=info msg=&quot;capturing logs&quot; argo=true
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: 
https://pip.pypa.io/warnings/venv
[KFP Executor 2022-04-26 17:38:24,691 INFO]: Looking for component `run_info_fn` in --component_module_path `/tmp/tmp.NJW6PWXpIt/ephemeral_component.py`
[KFP Executor 2022-04-26 17:38:24,691 INFO]: Loading KFP component &quot;run_info_fn&quot; from /tmp/tmp.NJW6PWXpIt/ephemeral_component.py (directory &quot;/tmp/tmp.NJW6PWXpIt&quot; and module name &quot;ephemeral_component&quot;)
Traceback (most recent call last):
  File &quot;/usr/local/lib/python3.7/runpy.py&quot;, line 193, in _run_module_as_main
    &quot;__main__&quot;, mod_spec)
  File &quot;/usr/local/lib/python3.7/runpy.py&quot;, line 85, in _run_code
    exec(code, run_globals)
  File &quot;/usr/local/lib/python3.7/site-packages/kfp/v2/components/executor_main.py&quot;, line 104, in &lt;module&gt;
    executor_main()
  File &quot;/usr/local/lib/python3.7/site-packages/kfp/v2/components/executor_main.py&quot;, line 94, in executor_main
    executor_input = json.loads(args.executor_input)
  File &quot;/usr/local/lib/python3.7/json/__init__.py&quot;, line 348, in loads
    return _default_decoder.decode(s)
  File &quot;/usr/local/lib/python3.7/json/decoder.py&quot;, line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File &quot;/usr/local/lib/python3.7/json/decoder.py&quot;, line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)
time=&quot;2022-04-26T17:38:24.803Z&quot; level=error msg=&quot;cannot save artifact /tmp/outputs/run_info/data&quot; argo=true error=&quot;stat /tmp/outputs/run_info/data: no such file or directory&quot;
Error: exit status 1
</code></pre>
<p>Here's the files to repro:
root_pipeline_04d99580c84b47c28405a2c8bcae8703.py</p>
<pre><code>import kfp.v2.components
from kfp.v2.dsl import InputPath
from kubernetes.client.models import V1EnvVar
from kubernetes import client, config
from typing import NamedTuple
from base64 import b64encode
import kfp.v2.dsl as dsl
import kubernetes
import json
import kfp

from run_info import run_info_fn
from same_step_000_ce6494722c474dd3b8bef482bb976557 import same_step_000_ce6494722c474dd3b8bef482bb976557_fn


run_info_comp = kfp.v2.dsl.component(
    func=run_info_fn,
    packages_to_install=[
        &quot;kfp&quot;,
        &quot;dill&quot;,
    ],
)

same_step_000_ce6494722c474dd3b8bef482bb976557_comp = kfp.v2.dsl.component(
    func=same_step_000_ce6494722c474dd3b8bef482bb976557_fn,
    base_image=&quot;public.ecr.aws/j1r0q0g6/notebooks/notebook-servers/codeserver-python:v1.5.0&quot;,
    packages_to_install=[
        &quot;dill&quot;,
        &quot;requests&quot;,
         # TODO: make this a loop
    ],
)

@kfp.dsl.pipeline(name=&quot;root_pipeline_compilation&quot;,)
def root(
    context: str='', metadata_url: str='',
):
    # Generate secrets (if not already created)
    secrets_by_env = {}

    env_vars = {
    }

    run_info = run_info_comp(run_id=kfp.dsl.RUN_ID_PLACEHOLDER)


    same_step_000_ce6494722c474dd3b8bef482bb976557 = same_step_000_ce6494722c474dd3b8bef482bb976557_comp(
        input_context_path=&quot;&quot;,
        run_info=run_info.outputs[&quot;run_info&quot;],
        metadata_url=metadata_url
    )

    same_step_000_ce6494722c474dd3b8bef482bb976557.execution_options.caching_strategy.max_cache_staleness = &quot;P0D&quot;
    for k in env_vars:
        same_step_000_ce6494722c474dd3b8bef482bb976557.add_env_variable(V1EnvVar(name=k, value=env_vars[k]))

</code></pre>
<p>run_info.py</p>
<pre><code>&quot;&quot;&quot;
The run_info component fetches metadata about the current pipeline execution
from kubeflow and passes it on to the user code step components.
&quot;&quot;&quot;
from typing import NamedTuple


def run_info_fn(
    run_id: str,
) -&gt; NamedTuple(&quot;RunInfoOutput&quot;, [(&quot;run_info&quot;, str),]):
    from base64 import urlsafe_b64encode
    from collections import namedtuple
    import datetime
    import base64
    import dill
    import kfp

    client = kfp.Client(host=&quot;http://ml-pipeline:8888&quot;)
    run_info = client.get_run(run_id=run_id)

    run_info_dict = {
        &quot;run_id&quot;: run_info.run.id,
        &quot;name&quot;: run_info.run.name,
        &quot;created_at&quot;: run_info.run.created_at.isoformat(),
        &quot;pipeline_id&quot;: run_info.run.pipeline_spec.pipeline_id,
    }

    # Track kubernetes resources associated wth the run.
    for r in run_info.run.resource_references:
        run_info_dict[f&quot;{r.key.type.lower()}_id&quot;] = r.key.id

    # Base64-encoded as value is visible in kubeflow ui.
    output = urlsafe_b64encode(dill.dumps(run_info_dict))

    return namedtuple(&quot;RunInfoOutput&quot;, [&quot;run_info&quot;])(
        str(output, encoding=&quot;ascii&quot;)
    )
</code></pre>
<p>same_step_000_ce6494722c474dd3b8bef482bb976557.py</p>
<pre><code>import kfp
from kfp.v2.dsl import component, Artifact, Input, InputPath, Output, OutputPath, Dataset, Model
from typing import NamedTuple


def same_step_000_ce6494722c474dd3b8bef482bb976557_fn(
    input_context_path: InputPath(str),
    output_context_path: OutputPath(str),
    run_info: str = &quot;gAR9lC4=&quot;,
    metadata_url: str = &quot;&quot;,
):
    from base64 import urlsafe_b64encode, urlsafe_b64decode
    from pathlib import Path
    import datetime
    import requests
    import tempfile
    import dill
    import os

    input_context = None
    with Path(input_context_path).open(&quot;rb&quot;) as reader:
        input_context = reader.read()

    # Helper function for posting metadata to mlflow.
    def post_metadata(json):
        if metadata_url == &quot;&quot;:
            return

        try:
            req = requests.post(metadata_url, json=json)
            req.raise_for_status()
        except requests.exceptions.HTTPError as err:
            print(f&quot;Error posting metadata: {err}&quot;)

    # Move to writable directory as user might want to do file IO.
    # TODO: won't persist across steps, might need support in SDK?
    os.chdir(tempfile.mkdtemp())

    # Load information about the current experiment run:
    run_info = dill.loads(urlsafe_b64decode(run_info))

    # Post session context to mlflow.
    if len(input_context) &gt; 0:
        input_context_str = urlsafe_b64encode(input_context)
        post_metadata(
            {
                &quot;experiment_id&quot;: run_info[&quot;experiment_id&quot;],
                &quot;run_id&quot;: run_info[&quot;run_id&quot;],
                &quot;step_id&quot;: &quot;same_step_000&quot;,
                &quot;metadata_type&quot;: &quot;input&quot;,
                &quot;metadata_value&quot;: input_context_str,
                &quot;metadata_time&quot;: datetime.datetime.now().isoformat(),
            }
        )

    # User code for step, which we run in its own execution frame.
    user_code = f&quot;&quot;&quot;
import dill

# Load session context into global namespace:
if { len(input_context) } &gt; 0:
    dill.load_session(&quot;{ input_context_path }&quot;)

{dill.loads(urlsafe_b64decode(&quot;gASVGAAAAAAAAACMFHByaW50KCJIZWxsbyB3b3JsZCIplC4=&quot;))}

# Remove anything from the global namespace that cannot be serialised.
# TODO: this will include things like pandas dataframes, needs sdk support?
_bad_keys = []
_all_keys = list(globals().keys())
for k in _all_keys:
    try:
        dill.dumps(globals()[k])
    except TypeError:
        _bad_keys.append(k)

for k in _bad_keys:
    del globals()[k]

# Save new session context to disk for the next component:
dill.dump_session(&quot;{output_context_path}&quot;)
&quot;&quot;&quot;

    # Runs the user code in a new execution frame. Context from the previous
    # component in the run is loaded into the session dynamically, and we run
    # with a single globals() namespace to simulate top-level execution.
    exec(user_code, globals(), globals())

    # Post new session context to mlflow:
    with Path(output_context_path).open(&quot;rb&quot;) as reader:
        context = urlsafe_b64encode(reader.read())
        post_metadata(
            {
                &quot;experiment_id&quot;: run_info[&quot;experiment_id&quot;],
                &quot;run_id&quot;: run_info[&quot;run_id&quot;],
                &quot;step_id&quot;: &quot;same_step_000&quot;,
                &quot;metadata_type&quot;: &quot;output&quot;,
                &quot;metadata_value&quot;: context,
                &quot;metadata_time&quot;: datetime.datetime.now().isoformat(),
            }
        )
</code></pre>
<p>Python file to execute to run:</p>
<pre><code>from sameproject.ops import helpers
from pathlib import Path
import importlib
import kfp


def deploy(compiled_path: Path, root_module_name: str):
    with helpers.add_path(str(compiled_path)):
        kfp_client = kfp.Client()  # only supporting 'kubeflow' namespace
        root_module = importlib.import_module(root_module_name)

        return kfp_client.create_run_from_pipeline_func(
            root_module.root,
            arguments={},
        )
</code></pre>

aronchick
<p>Turns out it has to do with not compiling with the right execution mode on.</p>
<p>If you're getting this, your code should look like this.</p>
<pre><code>Compiler(mode=kfp.dsl.PipelineExecutionMode.V2_COMPATIBLE).compile(pipeline_func=root_module.root, package_path=str(package_yaml_path))

</code></pre>
