argoproj / argo-workflows

Workflow Engine for Kubernetes
https://argo-workflows.readthedocs.io/
Apache License 2.0
14.85k stars 3.17k forks source link

Invalid value type in api response ['received_data']['status'] #7293

Closed 66li closed 2 years ago

66li commented 2 years ago

Summary

I tried to run the python-client example. used kubectl port-forward to forward the workflow port to the local. When I ran the following code, the workflow was successfully created but I got some errors.

from pprint import pprint

import requests
import yaml

import openapi_client
from openapi_client.api import workflow_service_api
from openapi_client.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
    IoArgoprojWorkflowV1alpha1WorkflowCreateRequest

Token = "Bearer eyJhbGciOiJSUzI1NiIs.."
configuration = openapi_client.Configuration(host="http://127.0.0.1:2746")

configuration.verify_ssl = False

resp = requests.get('https://raw.githubusercontent.com/argoproj/argo-workflows/master/examples/hello-world.yaml')
manifest = yaml.safe_load(resp.text)
#manifest['spec']['serviceAccountName'] = 'argo'

api_client = openapi_client.ApiClient(configuration,"Authorization",Token)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)
print("test")
api_response = api_instance.workflow_service_create_workflow(
    namespace='argo',
    body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(
        workflow=manifest, _check_type=False))
pprint(api_response)
Traceback (most recent call last):
  File "/Users/cwcw/feishu-bot/oprate.py", line 24, in <module>
    api_response = api_instance.workflow_service_create_workflow(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/api_client.py", line 771, in __call__
    return self.callable(self, *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/api/workflow_service_api.py", line 121, in __workflow_service_create_workflow
    return self.call_with_http_info(**kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/api_client.py", line 833, in call_with_http_info
    return self.api_client.call_api(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/api_client.py", line 408, in call_api
    return self.__call_api(resource_path, method,
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/api_client.py", line 223, in __call_api
    return_data = self.deserialize(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/api_client.py", line 324, in deserialize
    deserialized_data = validate_and_convert_types(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1540, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1436, in attempt_convert_item
    raise conversion_exc
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1427, in attempt_convert_item
    return deserialize_model(input_value, valid_class,
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1347, in deserialize_model
    return model_class._new_from_openapi_data(**kw_args)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 44, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 343, in _new_from_openapi_data
    return cls._from_openapi_data(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 44, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model/io_argoproj_workflow_v1alpha1_workflow.py", line 198, in _from_openapi_data
    setattr(self, var_name, var_value)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 183, in __setattr__
    self[attr] = value
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 483, in __setitem__
    self.set_attribute(name, value)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 155, in set_attribute
    value = validate_and_convert_types(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1540, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1436, in attempt_convert_item
    raise conversion_exc
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1427, in attempt_convert_item
    return deserialize_model(input_value, valid_class,
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1347, in deserialize_model
    return model_class._new_from_openapi_data(**kw_args)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 44, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 343, in _new_from_openapi_data
    return cls._from_openapi_data(*args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 44, in wrapped_init
    return fn(_self, *args, **kwargs)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model/io_argoproj_workflow_v1alpha1_workflow_status.py", line 240, in _from_openapi_data
    setattr(self, var_name, var_value)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 183, in __setattr__
    self[attr] = value
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 483, in __setitem__
    self.set_attribute(name, value)
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 155, in set_attribute
    value = validate_and_convert_types(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1540, in validate_and_convert_types
    converted_instance = attempt_convert_item(
  File "/opt/homebrew/lib/python3.9/site-packages/openapi_client/model_utils.py", line 1422, in attempt_convert_item
    raise get_type_error(input_value, path_to_item, valid_classes,
openapi_client.exceptions.ApiTypeError: Invalid type for variable 'started_at'. Required value type is datetime and passed type was NoneType at ['received_data']['status']['started_at']
terrytangyuan commented 2 years ago

Thanks for reporting. Yes this is a known issue and I haven't got a chance to fix it yet. Feel free to submit a PR if you can locate that root cause.

terrytangyuan commented 2 years ago

Possibly related issues with OpenAPI generator:

terrytangyuan commented 2 years ago

cc @flaviuvadan since you have fixed a similar issue in Hera.

flaviuvadan commented 2 years ago

@66li try to submit it with:

api_response = api_instance.workflow_service_create_workflow(
    namespace='argo',
    body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(
        workflow=manifest, _check_return_type=False))
dixon1e commented 2 years ago

Just a quick heads up. I was demonstrating to someone and decided to run this code again, including the line:

body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest, _check_return_type=False, _check_type=False))

But I received the same error as the original reporter. This is the example code from the repo:

#!/usr/bin/env python
#import json
from pprint import pprint

import argo_workflows
from argo_workflows.api import workflow_service_api
from argo_workflows.model.io_argoproj_workflow_v1alpha1_workflow_create_request import \
    IoArgoprojWorkflowV1alpha1WorkflowCreateRequest
import requests
import yaml

configuration = argo_workflows.Configuration(host="https://127.0.0.1:2746")
configuration.verify_ssl = False

resp = requests.get('https://raw.githubusercontent.com/argoproj/argo-workflows/master/examples/hello-world.yaml')
manifest = yaml.safe_load(resp.text)
# print(json.dumps(manifest, indent=4))

api_client = argo_workflows.ApiClient(configuration)
api_instance = workflow_service_api.WorkflowServiceApi(api_client)

api_response = api_instance.create_workflow(
    namespace='argo',
    body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest, _check_return_type=False, _check_type=False))
pprint(api_response)

To recreate, perhaps this script can help do it quickly:

#!/bin/bash
python3 -m venv venv3
. ./venv3/bin/activate
pip install -U pip
pip install \
    wheel \
    requests \
    pyyaml \
    git+https://github.com/argoproj/argo-workflows@master#subdirectory=sdks/python/client
#
python example.py

I am hopeful there is simply a step I missed somewhere.

terrytangyuan commented 2 years ago

@flaviuvadan Could you double-check on this when you start migrating to the new SDK?

flaviuvadan commented 2 years ago

Hey @dixon1e! I think the call should be:

api_response = api_instance.create_workflow(
    namespace='argo',
    body=IoArgoprojWorkflowV1alpha1WorkflowCreateRequest(workflow=manifest, _check_type=False), _check_return_type=False)

The _check_return_type=False goes on the create_workflow call rather than the body specification.

dixon1e commented 2 years ago

@flaviuvadan I will check ASAP.

terrytangyuan commented 2 years ago

Great catch! I am fixing the examples in https://github.com/argoproj/argo-workflows/pull/7731.

dixon1e commented 2 years ago

Confirmed moving the parameters to the correct call removes the error. The code we (@66li and I) used is the example code in the README, specifically argo-workflows/sdks/python/README.md.

EDIT: I see @terrytangyuan has fixed the doco, well done.

terrytangyuan commented 2 years ago

Great to hear. Thanks for spotting it @dixon1e and @flaviuvadan for taking a quick look!